diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/C4Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/C4Entity.java index 9dba40b8d..23b67e5b9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/C4Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/C4Entity.java @@ -22,7 +22,6 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; @@ -38,10 +37,8 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab protected static final EntityDataAccessor> OWNER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.OPTIONAL_UUID); protected static final EntityDataAccessor LAST_ATTACKER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING); protected static final EntityDataAccessor> TARGET_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.OPTIONAL_UUID); - protected static final EntityDataAccessor REL_X = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT); - protected static final EntityDataAccessor REL_Y = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT); - protected static final EntityDataAccessor REL_Z = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT); + private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public C4Entity(EntityType type, Level world) { @@ -52,12 +49,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab public C4Entity(LivingEntity owner, Level level) { super(ModEntities.C_4.get(), level); this.setOwnerUUID(owner.getUUID()); - ModUtils.queueServerWork(1, () -> { - if (this.level().isClientSide()) return; - CompoundTag compoundTag = owner.serializeNBT(); - compoundTag.putUUID("C4UUID", this.getUUID()); - this.getOwner().deserializeNBT(compoundTag); - }); } @Override @@ -66,9 +57,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab this.entityData.define(LAST_ATTACKER_UUID, "undefined"); this.entityData.define(HEALTH, 10f); this.entityData.define(TARGET_UUID, Optional.empty()); - this.entityData.define(REL_X, 0.0f); - this.entityData.define(REL_Y, 0.0f); - this.entityData.define(REL_Z, 0.0f); } @Override @@ -109,9 +97,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID)); if (this.getTargetUUID() != null) { compound.putUUID("Target", this.getTargetUUID()); - compound.putFloat("RelativeX", this.entityData.get(REL_X)); - compound.putFloat("RelativeY", this.entityData.get(REL_Y)); - compound.putFloat("RelativeZ", this.entityData.get(REL_Z)); } if (this.getOwnerUUID() != null) { compound.putUUID("Owner", this.getOwnerUUID()); @@ -141,12 +126,11 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab if (uuid != null) { try { this.setOwnerUUID(uuid); - } catch (Throwable ignored){} + } catch (Throwable ignored) { + } } - /* - * Target - **/ + // Target if (compound.hasUUID("Target")) { uuid = compound.getUUID("Target"); } else { @@ -159,11 +143,8 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab if (uuid != null) { try { this.setTargetUUID(uuid); - - this.entityData.set(REL_X, compound.getFloat("RelativeX")); - this.entityData.set(REL_Y, compound.getFloat("RelativeY")); - this.entityData.set(REL_Z, compound.getFloat("RelativeZ")); - } catch (Throwable ignored){} + } catch (Throwable ignored) { + } } } @@ -171,14 +152,10 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab return this.onGround() || this.getTargetUUID() != null; } - @Override public void tick() { super.tick(); - var level = this.level(); - var x = this.getX(); - var y = this.getY(); - var z = this.getZ(); + Level level = this.level(); if (this.tickCount >= ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get()) { this.explode(); @@ -193,7 +170,7 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab if (this.getUUID() == target.getUUID() || this.getOwnerUUID() == target.getUUID() || !(target instanceof LivingEntity || target instanceof VehicleEntity)) { continue; } - this.setTargetUUID(target.getUUID());; + this.setTargetUUID(target.getUUID()); // var relpos = this.calcRelativePos(target); // this.setRelativePos(((float) relpos.x), ((float) relpos.y), ((float) relpos.z)); @@ -206,26 +183,22 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab this.destroy(); } } else { - ModUtils.queueServerWork(1, () -> { - if (level.isClientSide()) return; - if (this.getTargetUUID() == null) { - this.destroy(); - return; - } - Entity target = EntityFindUtil.findEntity(this.level(), this.getTargetUUID().toString()); - if (target == null) { - this.destroy(); - return; - } - if (!this.isInvisible()) { - this.setInvisible(true); - } - this.setPos(target.position().x, target.position().y + target.getBoundingBox().getYsize(), target.position().z); - }); + if (level.isClientSide()) return; + if (this.getTargetUUID() == null) { + this.destroy(); + return; + } + Entity target = EntityFindUtil.findEntity(this.level(), this.getTargetUUID().toString()); + if (target == null) { + this.destroy(); + return; + } + if (!this.isInvisible()) { + this.setInvisible(true); + } + this.setPos(target.position().x, target.position().y + target.getBoundingBox().getYsize(), target.position().z); } - - this.refreshDimensions(); } @@ -243,23 +216,6 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab this.discard(); } - public Vec3 getRelativePos() { - if (this.isPlaced()) { - return new Vec3(this.entityData.get(REL_X), this.entityData.get(REL_Y), this.entityData.get(REL_Z)); - } - return null; - } - - public Vec3 calcRelativePos(Entity target) { - return this.position().subtract(target.position()); - } - - public void setRelativePos(float x, float y, float z) { - this.entityData.set(REL_X, x); - this.entityData.set(REL_X, y); - this.entityData.set(REL_X, z); - } - public void destroy() { if (this.level() instanceof ServerLevel && this.tickCount < ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get()) { ItemEntity c4 = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), new ItemStack(ModItems.C4_BOMB.get())); @@ -275,7 +231,7 @@ public class C4Entity extends Entity implements GeoEntity, AnimatedEntity, Ownab target.getX(), target.getY(), target.getZ(), ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(level(), explosion); - ParticleTool.spawnHugeExplosionParticles(level(),position()); + ParticleTool.spawnHugeExplosionParticles(level(), position()); explosion.finalizeExplosion(false); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java index 4dc9351ba..f68271eb9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java @@ -69,6 +69,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor DELTA_X_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor PROPELLER_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); + private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = 5; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index f1173f7f6..d6948e665 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -63,13 +63,14 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = VehicleConfig.AH_6_HP.get(); public static final int MAX_ENERGY = VehicleConfig.AH_6_MAX_ENERGY.get(); + public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor PROPELLER_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor WEAPON_TYPE = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT); - public static final EntityDataAccessor AMMO = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor DECOY_COUNT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor LOADED_ROCKET = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT); + public boolean engineStart; public boolean engineStartOver; public float propellerRot; @@ -106,16 +107,16 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli public void addAdditionalSaveData(CompoundTag compound) { super.addAdditionalSaveData(compound); compound.putInt("LoadedRocket", this.entityData.get(LOADED_ROCKET)); - compound.putFloat("propellerRot", this.entityData.get(PROPELLER_ROT)); - compound.putInt("decoyCount", this.entityData.get(DECOY_COUNT)); + compound.putFloat("PropellerRot", this.entityData.get(PROPELLER_ROT)); + compound.putInt("DecoyCount", this.entityData.get(DECOY_COUNT)); } @Override public void readAdditionalSaveData(CompoundTag compound) { super.readAdditionalSaveData(compound); this.entityData.set(LOADED_ROCKET, compound.getInt("LoadedRocket")); - this.entityData.set(PROPELLER_ROT, compound.getFloat("propellerRot")); - this.entityData.set(DECOY_COUNT, compound.getInt("decoyCount")); + this.entityData.set(PROPELLER_ROT, compound.getFloat("PropellerRot")); + this.entityData.set(DECOY_COUNT, compound.getInt("DecoyCount")); } @Override @@ -227,7 +228,7 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0); for (int i = 0; i < 4; i++) { FlareDecoyEntity flareDecoyEntity = new FlareDecoyEntity((LivingEntity) passenger, this.level()); - flareDecoyEntity.setPos(this.getX() + this.getDeltaMovement().x, this.getY() + 0.5 + this.getDeltaMovement().y, this.getZ()+ this.getDeltaMovement().z); + flareDecoyEntity.setPos(this.getX() + this.getDeltaMovement().x, this.getY() + 0.5 + this.getDeltaMovement().y, this.getZ() + this.getDeltaMovement().z); flareDecoyEntity.decoyShoot(this, this.getViewVector(1).yRot((45 + 90 * i) * Mth.DEG_TO_RAD), 0.8f, 8); this.level().addFreshEntity(flareDecoyEntity); } @@ -239,16 +240,11 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli } decoyInputDown = false; } - if (this.entityData.get(DECOY_COUNT) < 6 && decoyReloadCoolDown == 0 && this.level() instanceof ServerLevel) { + if (this.entityData.get(DECOY_COUNT) < 6 && decoyReloadCoolDown == 0 && this.level() instanceof ServerLevel) { this.entityData.set(DECOY_COUNT, this.entityData.get(DECOY_COUNT) + 1); this.level().playSound(null, this, ModSounds.DECOY_RELOAD.get(), this.getSoundSource(), 1, 1); decoyReloadCoolDown = 300; } -// Player player = (Player) this.getFirstPassenger(); -// -// if (player != null) { -// player.displayClientMessage(Component.literal( new DecimalFormat("##").format(this.getEntityData().get(DECOY_COUNT))), true); -// } } @Override @@ -266,7 +262,6 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli this.setXRot(this.getXRot() * 0.8f); this.entityData.set(POWER, this.entityData.get(POWER) * 0.98f); } else if (passenger instanceof Player) { - diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot())); diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot())); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java index 308c1b1bb..115af7e83 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/ContainerMobileEntity.java @@ -67,10 +67,6 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus if (player.getVehicle() == this) return InteractionResult.PASS; ItemStack stack = player.getMainHandItem(); - if (stack.is(ModItems.C4_BOMB.get())) { - stack.use(player.level(), player, hand); - return InteractionResult.SUCCESS; - } if (player.isShiftKeyDown() && stack.is(ModItems.CROWBAR.get())) { ItemStack container = ContainerBlockItem.createInstance(this); if (!player.addItem(container)) { @@ -132,13 +128,6 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus } }) ); - -// Player player = (Player) this.getFirstPassenger(); - -// if (player != null) { -// player.displayClientMessage(Component.literal( new DecimalFormat("##.#").format(this.getEnergy())), true); -// } - this.refreshDimensions(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java index 7f7c6544f..bbe8658ac 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java @@ -1,7 +1,5 @@ package com.atsuishio.superbwarfare.entity.vehicle; -import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.entity.C4Entity; import com.atsuishio.superbwarfare.entity.DroneEntity; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModItems; @@ -56,6 +54,7 @@ public class VehicleEntity extends Entity { public float prevRoll; public int lastHurtTick; public boolean crash; + public float getRoll() { return roll; } @@ -224,8 +223,7 @@ public class VehicleEntity extends Entity { @Override protected boolean canAddPassenger(Entity pPassenger) { - ModUtils.LOGGER.info(pPassenger.getClass().toString()); - return this.getPassengers().size() < this.getMaxPassengers() || pPassenger instanceof C4Entity; + return this.getPassengers().size() < this.getMaxPassengers(); } public int getMaxPassengers() { @@ -236,9 +234,9 @@ public class VehicleEntity extends Entity { public void baseTick() { super.baseTick(); - lastHurtTick ++; + this.lastHurtTick++; - prevRoll = this.getRoll(); + this.prevRoll = this.getRoll(); float delta = Math.abs(getYRot() - yRotO); while (getYRot() > 180F) { @@ -312,9 +310,9 @@ public class VehicleEntity extends Entity { } } - if (this.getHealth() < 0.1f * this.getMaxHealth() && tickCount %13 == 0) { + if (this.getHealth() < 0.1f * this.getMaxHealth() && tickCount % 13 == 0) { this.level().playSound(null, this.getOnPos(), ModSounds.NO_HEALTH.get(), SoundSource.PLAYERS, 1, 1); - } else if (this.getHealth() >= 0.1f && this.getHealth() < 0.4f * this.getMaxHealth() && tickCount %10 == 0) { + } else if (this.getHealth() >= 0.1f && this.getHealth() < 0.4f * this.getMaxHealth() && tickCount % 10 == 0) { this.level().playSound(null, this.getOnPos(), ModSounds.LOW_HEALTH.get(), SoundSource.PLAYERS, 1, 1); } }