优化载具类

This commit is contained in:
Atsuihsio 2024-12-27 23:20:02 +08:00
parent 3a90f84a0e
commit 7bbf8138c9
19 changed files with 462 additions and 580 deletions

View file

@ -1,7 +1,6 @@
package com.atsuishio.superbwarfare.client.layer;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.AnnihilatorEntity;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@ -25,8 +24,8 @@ public class AnnihilatorPowerLayer extends GeoRenderLayer<AnnihilatorEntity> {
@Override
public void render(PoseStack poseStack, AnnihilatorEntity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
RenderType glowRenderType = RenderType.entityTranslucent(LAYER);
float red = 1 - Mth.clamp(2.5f * animatable.getEntityData().get(AnnihilatorEntity.ENERGY)/ CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue(),0,1);
float green = Mth.clamp(2.5f * animatable.getEntityData().get(AnnihilatorEntity.ENERGY)/ CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue(),0,1);
float red = 1 - Mth.clamp(2.5f * animatable.getEnergy()/ animatable.getMaxEnergy(),0,1);
float green = Mth.clamp(2.5f * animatable.getEnergy()/ animatable.getMaxEnergy(),0,1);
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, red, green, 0, 1);
}
}

View file

@ -1,7 +1,6 @@
package com.atsuishio.superbwarfare.client.layer;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.AnnihilatorEntity;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@ -25,8 +24,8 @@ public class AnnihilatorPowerLightLayer extends GeoRenderLayer<AnnihilatorEntity
@Override
public void render(PoseStack poseStack, AnnihilatorEntity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
RenderType glowRenderType = RenderType.eyes(LAYER);
float red = 1 - Mth.clamp(2.5f * animatable.getEntityData().get(AnnihilatorEntity.ENERGY)/ CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue(),0,1);
float green = Mth.clamp(2.5f * animatable.getEntityData().get(AnnihilatorEntity.ENERGY)/ CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue(),0,1);
float red = 1 - Mth.clamp(2.5f * animatable.getEnergy()/ animatable.getMaxEnergy(),0,1);
float green = Mth.clamp(2.5f * animatable.getEnergy()/ animatable.getMaxEnergy(),0,1);
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, red, green, 0, 1);
}
}

View file

@ -1,7 +1,6 @@
package com.atsuishio.superbwarfare.client.layer;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.Mk42Entity;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@ -25,7 +24,7 @@ public class Mk42DamageLayer extends GeoRenderLayer<Mk42Entity> {
@Override
public void render(PoseStack poseStack, Mk42Entity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
RenderType glowRenderType = RenderType.entityTranslucent(LAYER);
float heal = Mth.clamp((0.3f * CannonConfig.MK42_HP.get() - animatable.getEntityData().get(Mk42Entity.HEALTH)) * 0.00001f * CannonConfig.MK42_HP.get(), 0f, 1);
float heal = Mth.clamp((0.3f * animatable.getMaxHealth() - animatable.getHealth()) * 0.00001f * animatable.getMaxHealth(), 0, 1);
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, heal);
}
}

View file

@ -1,7 +1,6 @@
package com.atsuishio.superbwarfare.client.layer;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.Mle1934Entity;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@ -25,7 +24,7 @@ public class Mle1934DamageLayer extends GeoRenderLayer<Mle1934Entity> {
@Override
public void render(PoseStack poseStack, Mle1934Entity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
RenderType glowRenderType = RenderType.entityTranslucent(LAYER);
float heal = Mth.clamp((0.3f * CannonConfig.MLE1934_HP.get() - animatable.getEntityData().get(Mle1934Entity.HEALTH)) * 0.00001f * CannonConfig.MLE1934_HP.get(), 0, 1);
float heal = Mth.clamp((0.3f * animatable.getMaxHealth() - animatable.getHealth()) * 0.00001f * animatable.getMaxHealth(), 0, 1);
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, heal);
}
}

View file

@ -12,8 +12,6 @@ import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.renderer.GeoRenderer;
import software.bernie.geckolib.renderer.layer.GeoRenderLayer;
import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.ENERGY;
public class SpeedBoatPowerLayer extends GeoRenderLayer<SpeedboatEntity> {
private static final ResourceLocation LAYER = ModUtils.loc("textures/entity/speedboat_power.png");
@ -24,7 +22,7 @@ public class SpeedBoatPowerLayer extends GeoRenderLayer<SpeedboatEntity> {
@Override
public void render(PoseStack poseStack, SpeedboatEntity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
if (animatable.getEntityData().get(ENERGY) <= 0) return;
if (animatable.getEnergy() <= 0) return;
RenderType glowRenderType = RenderType.eyes(LAYER);
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
}

View file

@ -1,7 +1,6 @@
package com.atsuishio.superbwarfare.client.model.entity;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.AnnihilatorEntity;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
@ -74,7 +73,7 @@ public class AnnihilatorModel extends GeoModel<AnnihilatorEntity> {
CoreGeoBone ledRed5 = getAnimationProcessor().getBone("ledred5");
float coolDown = animatable.getEntityData().get(COOL_DOWN);
boolean cantShoot = animatable.getEntityData().get(ENERGY) < CannonConfig.ANNIHILATOR_SHOOT_COST.get().floatValue();
boolean cantShoot = animatable.getEnergy() < animatable.getMaxEnergy();
ledGreen.setHidden(coolDown > 80 || cantShoot);
ledGreen2.setHidden(coolDown > 60 || cantShoot);

View file

@ -1,10 +1,7 @@
package com.atsuishio.superbwarfare.client.screens;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.entity.ICannonEntity;
import com.atsuishio.superbwarfare.entity.IChargeEntity;
import com.atsuishio.superbwarfare.entity.IVehicleEntity;
import com.atsuishio.superbwarfare.entity.SpeedboatEntity;
import com.atsuishio.superbwarfare.entity.*;
import com.atsuishio.superbwarfare.init.ModItems;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
@ -57,17 +54,17 @@ public class VehicleHudOverlay {
GuiGraphics guiGraphics = event.getGuiGraphics();
guiGraphics.pose().pushPose();
if (vehicle instanceof IChargeEntity iCharge) {
energy = iCharge.getEnergy();
maxEnergy = iCharge.getMaxEnergy();
if (vehicle instanceof EnergyVehicleEntity energyVehicleEntity) {
energy = energyVehicleEntity.getEnergy();
maxEnergy = energyVehicleEntity.getMaxEnergy();
guiGraphics.blit(ENERGY, w - 96, h - 28, 0, 0, 12, 12, 12, 12);
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 26, 0, 0, 80, 8, 80, 8);
guiGraphics.blit(HEALTH, w - 83, h - 26, 0, 0, (int) (80 * energy / maxEnergy), 8, 80, 8);
}
if (vehicle instanceof IVehicleEntity iVehicle) {
health = iVehicle.getHealth();
maxHealth = iVehicle.getMaxHealth();
if (vehicle instanceof VehicleEntity pVehicle) {
health = pVehicle.getHealth();
maxHealth = pVehicle.getMaxHealth();
guiGraphics.blit(ARMOR, w - 96, h - 14, 0, 0, 12, 12, 12, 12);
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 12, 0, 0, 80, 8, 80, 8);
guiGraphics.blit(HEALTH, w - 83, h - 12, 0, 0, (int) (80 * health / maxHealth), 8, 80, 8);

View file

@ -21,12 +21,12 @@ public class CannonConfig {
public static ForgeConfigSpec.IntValue MLE1934_HE_EXPLOSION_RADIUS;
public static ForgeConfigSpec.IntValue ANNIHILATOR_HP;
public static ForgeConfigSpec.DoubleValue ANNIHILATOR_SHOOT_COST;
public static ForgeConfigSpec.DoubleValue ANNIHILATOR_MAX_ENERGY;
public static ForgeConfigSpec.IntValue ANNIHILATOR_SHOOT_COST;
public static ForgeConfigSpec.IntValue ANNIHILATOR_MAX_ENERGY;
public static ForgeConfigSpec.IntValue SPEEDBOAT_HP;
public static ForgeConfigSpec.DoubleValue SPEEDBOAT_ENERGY_COST;
public static ForgeConfigSpec.DoubleValue SPEEDBOAT_MAX_ENERGY;
public static ForgeConfigSpec.IntValue SPEEDBOAT_ENERGY_COST;
public static ForgeConfigSpec.IntValue SPEEDBOAT_MAX_ENERGY;
public static ForgeConfigSpec.IntValue SPEEDBOAT_GUN_DAMAGE;
public static void init(ForgeConfigSpec.Builder builder) {
@ -86,10 +86,10 @@ public class CannonConfig {
ANNIHILATOR_HP = builder.defineInRange("annihilator_hp", 4000, 1, 10000000);
builder.comment("The energy cost of Annihilator per shoot");
ANNIHILATOR_SHOOT_COST = builder.defineInRange("annihilator_shoot_cost", 2000000d, 0d, Double.POSITIVE_INFINITY);
ANNIHILATOR_SHOOT_COST = builder.defineInRange("annihilator_shoot_cost", 2000000, 0, 2147483647);
builder.comment("The max energy storage of Annihilator");
ANNIHILATOR_MAX_ENERGY = builder.defineInRange("annihilator_max_energy", 20000000d, 0d, Double.POSITIVE_INFINITY);
ANNIHILATOR_MAX_ENERGY = builder.defineInRange("annihilator_max_energy", 20000000, 0, 2147483647);
builder.pop();
@ -99,10 +99,10 @@ public class CannonConfig {
SPEEDBOAT_HP = builder.defineInRange("speedboat_hp", 300, 1, 10000000);
builder.comment("The energy cost of Speedboat per control tick");
SPEEDBOAT_ENERGY_COST = builder.defineInRange("speedboat_energy_cost", 1d, 0d, Double.POSITIVE_INFINITY);
SPEEDBOAT_ENERGY_COST = builder.defineInRange("speedboat_energy_cost", 1, 0, 2147483647);
builder.comment("The max energy storage of Speedboat");
SPEEDBOAT_MAX_ENERGY = builder.defineInRange("speedboat_max_energy", 100000d, 0d, Double.POSITIVE_INFINITY);
SPEEDBOAT_MAX_ENERGY = builder.defineInRange("speedboat_max_energy", 100000, 0, 2147483647);
builder.comment("The gun damage of Speedboat");
SPEEDBOAT_GUN_DAMAGE = builder.defineInRange("speedboat_gun_damage", 45, 1, 10000000);

View file

@ -25,11 +25,12 @@ import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Explosion;
@ -51,24 +52,17 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator;
public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntity, IChargeEntity {
public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> LASER_LEFT_LENGTH = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> LASER_MIDDLE_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> OFFSET_ANGLE = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = CannonConfig.ANNIHILATOR_HP.get();
public static final float MAX_ENERGY = CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue();
public static final float SHOOT_COST = CannonConfig.ANNIHILATOR_SHOOT_COST.get().floatValue();
protected int interpolationSteps;
protected double serverYRot;
protected double serverXRot;
public static final int MAX_ENERGY = CannonConfig.ANNIHILATOR_MAX_ENERGY.get();
public static final int SHOOT_COST = CannonConfig.ANNIHILATOR_SHOOT_COST.get();
public Vec3 barrelLookAt;
public AnnihilatorEntity(PlayMessages.SpawnEntity packet, Level world) {
@ -82,31 +76,24 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(COOL_DOWN, 0);
this.entityData.define(HEALTH, MAX_HEALTH);
this.entityData.define(LASER_LEFT_LENGTH, 0f);
this.entityData.define(LASER_MIDDLE_LENGTH, 0f);
this.entityData.define(LASER_RIGHT_LENGTH, 0f);
this.entityData.define(ENERGY, 0f);
this.entityData.define(OFFSET_ANGLE, 0f);
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putInt("CoolDown", this.entityData.get(COOL_DOWN));
compound.putFloat("Health", this.entityData.get(HEALTH));
compound.putFloat("Energy", this.entityData.get(ENERGY));
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.entityData.set(COOL_DOWN, compound.getInt("CoolDown"));
this.entityData.set(ENERGY, compound.getFloat("Energy"));
if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health"));
} else {
this.entityData.set(HEALTH, MAX_HEALTH);
}
}
@Override
@ -118,16 +105,6 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
}
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean canCollideWith(Entity pEntity) {
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !this.isPassengerOfSameVehicle(pEntity);
}
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
@ -140,49 +117,30 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
@Override
public boolean hurt(DamageSource source, float amount) {
super.hurt(source, amount);
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
}
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.LIGHTNING_BOLT))
return false;
if (source.is(DamageTypes.FALLING_ANVIL))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
amount *= 0.5f;
}
if (source.is(ModDamageTypes.CANNON_FIRE)) {
amount *= 1.4f;
}
if (source.is(ModDamageTypes.GUN_FIRE)) {
amount = 0;
}
if (source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE)) {
amount *= 1.6f;
amount *= 0.1f;
}
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - 0.5f * Math.max(amount - 40, 0));
this.hurt(0.5f * Math.max(amount - 40, 0));
return true;
}
@Override
public boolean isPickable() {
return !this.isRemoved();
}
@Override
public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) {
@ -228,21 +186,21 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
}
if (this.level() instanceof ServerLevel serverLevel) {
if (this.entityData.get(HEALTH) <= 0.4 * CannonConfig.ANNIHILATOR_HP.get()) {
if (this.getHealth() <= 0.4 * this.getMaxHealth()) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
}
if (this.entityData.get(HEALTH) <= 0.25 * CannonConfig.ANNIHILATOR_HP.get()) {
if (this.getHealth() <= 0.25 * this.getMaxHealth()) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
}
if (this.entityData.get(HEALTH) <= 0.15 * CannonConfig.ANNIHILATOR_HP.get()) {
if (this.getHealth() <= 0.15 * this.getMaxHealth()) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
}
if (this.entityData.get(HEALTH) <= 0.1 * CannonConfig.ANNIHILATOR_HP.get()) {
if (this.getHealth() <= 0.1 * this.getMaxHealth()) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.FLAME, this.getX(), this.getY() + 3.2, this.getZ(), 4, 0.6, 0.1, 0.6, 0.05, false);
@ -250,9 +208,9 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
if (this.tickCount % 15 == 0) {
this.level().playSound(null, this.getOnPos(), SoundEvents.FIRE_AMBIENT, SoundSource.PLAYERS, 1, 1);
}
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - 0.1f);
this.hurt(0.1f);
} else {
this.entityData.set(HEALTH, Math.min(this.entityData.get(HEALTH) + 0.05f, MAX_HEALTH));
this.heal(0.05f);
}
}
@ -266,11 +224,6 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
yRotO = delta + getYRot();
}
if (this.entityData.get(HEALTH) <= 0) {
this.ejectPassengers();
destroy();
}
float yRot = this.getYRot();
if (yRot < 0) {
yRot += 360;
@ -313,8 +266,6 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
// travel();
// }
travel();
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
if (passenger instanceof ServerPlayer serverPlayer && this.entityData.get(COOL_DOWN) == 20) {
@ -386,16 +337,19 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
ParticleTool.spawnHugeExplosionParticles(this.level(), pos);
}
private void destroy() {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this), 160f,
this.getX(), this.getY(), this.getZ(), 20f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
this.discard();
@Override
public void destroy() {
if (level() instanceof ServerLevel) {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 200.0f,
this.getX(), this.getY(), this.getZ(), 15f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
this.discard();
}
}
@Override
@ -404,7 +358,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
return;
}
if (this.entityData.get(ENERGY) < SHOOT_COST) {
if (this.getEnergy() < SHOOT_COST) {
player.displayClientMessage(Component.literal("Not Enough Energy!"), true);
return;
}
@ -421,7 +375,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
this.entityData.set(COOL_DOWN, 100);
this.entityData.set(ENERGY, this.entityData.get(ENERGY) - SHOOT_COST);
this.extraEnergy(SHOOT_COST);
final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ());
@ -435,16 +389,10 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
}
@Override
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
serverYRot = yaw;
serverXRot = pitch;
this.interpolationSteps = 10;
}
public void travel() {
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
if (!(passenger instanceof LivingEntity entity)) return;
if (this.entityData.get(ENERGY) <= 0) return;
if (this.getEnergy() <= 0) return;
float yRot = this.getYRot();
if (yRot < 0) {
@ -552,34 +500,14 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
return this.cache;
}
@Override
public void charge(int amount) {
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue()));
}
@Override
public boolean canCharge() {
return this.entityData.get(ENERGY) < MAX_ENERGY;
}
@Override
public int getEnergy() {
return this.entityData.get(ENERGY).intValue();
}
@Override
public int getMaxEnergy() {
return (int) MAX_ENERGY;
}
@Override
public float getHealth() {
return this.entityData.get(HEALTH).intValue();
return MAX_ENERGY;
}
@Override
public float getMaxHealth() {
return (int) MAX_HEALTH;
return MAX_HEALTH;
}
@Override

View file

@ -230,8 +230,8 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity,
public void destroy() {
if (level() instanceof ServerLevel) {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), attacker,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker, attacker), 25.0f,
CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 25.0f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);

View file

@ -0,0 +1,62 @@
package com.atsuishio.superbwarfare.entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.Level;
import org.joml.Math;
public class EnergyVehicleEntity extends VehicleEntity implements IChargeEntity {
public static final EntityDataAccessor<Integer> ENERGY = SynchedEntityData.defineId(EnergyVehicleEntity.class, EntityDataSerializers.INT);
public EnergyVehicleEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
this.setEnergy(0);
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(ENERGY, this.getMaxEnergy());
}
@Override
protected void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.entityData.set(ENERGY, compound.getInt("Energy"));
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putFloat("Energy", this.entityData.get(ENERGY));
}
public void extraEnergy(int extraAmount) {
this.setEnergy(this.getEnergy() - extraAmount);
}
public int getEnergy() {
return this.entityData.get(ENERGY);
}
public void setEnergy(int pEnergy) {
this.entityData.set(ENERGY, Mth.clamp(pEnergy, 0, this.getMaxEnergy()));
}
public int getMaxEnergy() {
return 100000;
}
@Override
public void charge(int amount) {
this.setEnergy(Math.min(this.getEnergy() + amount, this.getMaxEnergy()));
}
@Override
public boolean canCharge() {
return this.getEnergy() < this.getMaxEnergy();
}
}

View file

@ -5,6 +5,4 @@ public interface IChargeEntity {
void charge(int amount);
boolean canCharge();
int getEnergy();
int getMaxEnergy();
}

View file

@ -6,10 +6,6 @@ public interface IVehicleEntity {
void vehicleShoot(Player player);
float getHealth();
float getMaxHealth();
boolean isDriver(Player player);
int mainGunRpm();

View file

@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.core.particles.ParticleTypes;
@ -26,10 +27,8 @@ import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
@ -50,18 +49,11 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator;
public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntity {
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);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get();
protected int interpolationSteps;
protected double serverYRot;
protected double serverXRot;
public Mk42Entity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.MK_42.get(), world);
}
@ -72,34 +64,20 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(COOL_DOWN, 0);
this.entityData.define(HEALTH, MAX_HEALTH);
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putInt("CoolDown", this.entityData.get(COOL_DOWN));
compound.putFloat("Health", this.entityData.get(HEALTH));
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
protected void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.entityData.set(COOL_DOWN, compound.getInt("CoolDown"));
if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health"));
} else {
this.entityData.set(HEALTH, MAX_HEALTH);
}
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean canCollideWith(Entity pEntity) {
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !this.isPassengerOfSameVehicle(pEntity);
}
@Override
@ -119,49 +97,29 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
@Override
public boolean hurt(DamageSource source, float amount) {
super.hurt(source, amount);
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
}
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.LIGHTNING_BOLT))
return false;
if (source.is(DamageTypes.FALLING_ANVIL))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
amount *= 0.5f;
}
if (source.is(ModDamageTypes.CANNON_FIRE)) {
amount *= 1.4f;
}
if (source.is(ModDamageTypes.GUN_FIRE)) {
amount *= 0.1f;
}
if (source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE)) {
amount *= 1.6f;
amount *= 0.5f;
}
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - 0.5f * Math.max(amount - 5, 0));
this.hurt(0.5f * Math.max(amount - 5, 0));
return true;
}
@Override
public boolean isPickable() {
return !this.isRemoved();
}
@Override
public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) {
@ -207,27 +165,27 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0));
}
if (this.entityData.get(HEALTH) <= 0.4 * CannonConfig.MK42_HP.get()) {
if (this.getHealth() <= 0.4 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
}
}
if (this.entityData.get(HEALTH) <= 0.25 * CannonConfig.MK42_HP.get()) {
if (this.getHealth() <= 0.25 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
}
}
if (this.entityData.get(HEALTH) <= 0.15 * CannonConfig.MK42_HP.get()) {
if (this.getHealth() <= 0.15 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
}
}
if (this.entityData.get(HEALTH) <= 0.1 * CannonConfig.MK42_HP.get()) {
if (this.getHealth() <= 0.1 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
@ -237,30 +195,27 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
if (this.tickCount % 15 == 0) {
this.level().playSound(null, this.getOnPos(), SoundEvents.FIRE_AMBIENT, SoundSource.PLAYERS, 1, 1);
}
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - 0.1f);
this.hurt(0.1f);
} else {
this.entityData.set(HEALTH, Math.min(this.entityData.get(HEALTH) + 0.05f, MAX_HEALTH));
this.heal(0.05f);
}
if (this.entityData.get(HEALTH) <= 0) {
this.ejectPassengers();
destroy();
}
travel();
this.refreshDimensions();
}
private void destroy() {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this), 130f,
this.getX(), this.getY(), this.getZ(), 9.5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
this.discard();
@Override
public void destroy() {
if (level() instanceof ServerLevel) {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 150.0f,
this.getX(), this.getY(), this.getZ(), 6f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.discard();
}
}
@Override
@ -358,12 +313,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
}
@Override
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
serverYRot = yaw;
serverXRot = pitch;
this.interpolationSteps = 10;
}
public void travel() {
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
@ -379,7 +328,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
}
protected void clampRotation(Entity entity) {
float f = Mth.wrapDegrees(entity.getXRot());
float f1 = Mth.clamp(f, -85.0F, 16.3F);
entity.xRotO += f1 - f;
@ -408,14 +356,9 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
return this.cache;
}
@Override
public float getHealth() {
return this.entityData.get(HEALTH).intValue();
}
@Override
public float getMaxHealth() {
return (int) MAX_HEALTH;
return MAX_HEALTH;
}
@Override

View file

@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.core.particles.ParticleTypes;
@ -26,10 +27,8 @@ import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
@ -51,19 +50,13 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator;
public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEntity {
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<Float> HEALTH = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = CannonConfig.MLE1934_HP.get();
protected int interpolationSteps;
protected double serverYRot;
protected double serverXRot;
public Mle1934Entity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.MLE_1934.get(), world);
}
@ -74,37 +67,23 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(COOL_DOWN, 0);
this.entityData.define(TYPE, 0);
this.entityData.define(HEALTH, MAX_HEALTH);
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putInt("CoolDown", this.entityData.get(COOL_DOWN));
compound.putInt("Type", this.entityData.get(TYPE));
compound.putFloat("Health", this.entityData.get(HEALTH));
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.entityData.set(COOL_DOWN, compound.getInt("CoolDown"));
this.entityData.set(TYPE, compound.getInt("Type"));
if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health"));
} else {
this.entityData.set(HEALTH, MAX_HEALTH);
}
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean canCollideWith(Entity pEntity) {
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !this.isPassengerOfSameVehicle(pEntity);
}
@Override
@ -133,49 +112,29 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
@Override
public boolean hurt(DamageSource source, float amount) {
super.hurt(source, amount);
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
}
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.LIGHTNING_BOLT))
return false;
if (source.is(DamageTypes.FALLING_ANVIL))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
amount *= 0.5f;
}
if (source.is(ModDamageTypes.CANNON_FIRE)) {
amount *= 1.4f;
}
if (source.is(ModDamageTypes.GUN_FIRE)) {
amount *= 0.1f;
}
if (source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE)) {
amount *= 1.6f;
amount *= 0.5f;
}
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - 0.5f * Math.max(amount - 5, 0));
this.hurt(0.5f * Math.max(amount - 5, 0));
return true;
}
@Override
public boolean isPickable() {
return !this.isRemoved();
}
@Override
public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) {
@ -221,27 +180,27 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0));
}
if (this.entityData.get(HEALTH) <= 0.4 * CannonConfig.MLE1934_HP.get()) {
if (this.getHealth() <= 0.4 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
}
}
if (this.entityData.get(HEALTH) <= 0.25 * CannonConfig.MLE1934_HP.get()) {
if (this.getHealth() <= 0.25 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
}
}
if (this.entityData.get(HEALTH) <= 0.15 * CannonConfig.MLE1934_HP.get()) {
if (this.getHealth() <= 0.15 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 1, 0.75, 0.5, 0.75, 0.01, false);
}
}
if (this.entityData.get(HEALTH) <= 0.1 * CannonConfig.MLE1934_HP.get()) {
if (this.getHealth() <= 0.1 * this.getMaxHealth()) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 2.5, this.getZ(), 2, 0.75, 0.5, 0.75, 0.01, false);
@ -251,30 +210,27 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
if (this.tickCount % 15 == 0) {
this.level().playSound(null, this.getOnPos(), SoundEvents.FIRE_AMBIENT, SoundSource.PLAYERS, 1, 1);
}
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - 0.1f);
this.hurt(0.1f);
} else {
this.entityData.set(HEALTH, Math.min(this.entityData.get(HEALTH) + 0.05f, MAX_HEALTH));
this.heal(0.05f);
}
if (this.entityData.get(HEALTH) <= 0) {
this.ejectPassengers();
destroy();
}
travel();
this.refreshDimensions();
}
private void destroy() {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this), 140f,
this.getX(), this.getY(), this.getZ(), 10f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
this.discard();
@Override
public void destroy() {
if (level() instanceof ServerLevel) {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 150.0f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.discard();
}
}
@Override
@ -451,12 +407,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
}
@Override
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
serverYRot = yaw;
serverXRot = pitch;
this.interpolationSteps = 10;
}
public void travel() {
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
if (!(passenger instanceof LivingEntity entity)) return;
@ -503,14 +453,9 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
return this.cache;
}
@Override
public float getHealth() {
return this.entityData.get(HEALTH).intValue();
}
@Override
public float getMaxHealth() {
return (int) MAX_HEALTH;
return MAX_HEALTH;
}
@Override

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
@ -14,18 +13,7 @@ import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.phys.Vec3;
import org.joml.Math;
public class MobileVehicleEntity extends Entity {
protected int interpolationSteps;
protected double x;
protected double y;
protected double z;
protected double serverYRot;
protected double serverXRot;
public float roll;
public class MobileVehicleEntity extends EnergyVehicleEntity {
public float power;
public boolean leftInputDown;
public boolean rightInputDown;
@ -33,68 +21,19 @@ public class MobileVehicleEntity extends Entity {
public boolean backInputDown;
public boolean upInputDown;
public boolean downInputDown;
public float roll;
public MobileVehicleEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean isPushable() {
return false;
}
@Override
public boolean isPickable() {
return !this.isRemoved();
}
@Override
public void baseTick() {
super.baseTick();
float delta = Math.abs(getYRot() - yRotO);
while (getYRot() > 180F) {
setYRot(getYRot() - 360F);
yRotO = getYRot() - delta;
}
while (getYRot() <= -180F) {
setYRot(getYRot() + 360F);
yRotO = delta + getYRot();
}
handleClientSync();
crushEntities(this.getDeltaMovement());
this.refreshDimensions();
}
protected void handleClientSync() {
if (isControlledByLocalInstance()) {
interpolationSteps = 0;
syncPacketPositionCodec(getX(), getY(), getZ());
}
if (interpolationSteps <= 0) {
return;
}
double interpolatedX = getX() + (x - getX()) / (double) interpolationSteps;
double interpolatedY = getY() + (y - getY()) / (double) interpolationSteps;
double interpolatedZ = getZ() + (z - getZ()) / (double) interpolationSteps;
double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot());
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
setPos(interpolatedX, interpolatedY, interpolatedZ);
setRot(getYRot(), getXRot());
--interpolationSteps;
}
/**
* 撞击实体并造成伤害
* @param velocity 动量
@ -122,38 +61,18 @@ public class MobileVehicleEntity extends Entity {
}
}
@Override
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
this.x = x;
this.y = y;
this.z = z;
serverYRot = yaw;
serverXRot = pitch;
this.interpolationSteps = 10;
}
public static double calculateAngle(Vec3 move, Vec3 view) {
move = move.multiply(1, 0, 1).normalize();
view = view.multiply(1, 0, 1).normalize();
double startLength = move.length();
double endLength = view.length();
if (startLength > 0.0D && endLength > 0.0D) {
return Math.toDegrees(Math.acos(Mth.clamp(move.dot(view) / (startLength * endLength), -1, 1)));
} else {
return 0.0D;
}
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
}
@Override
protected void readAdditionalSaveData(CompoundTag compoundTag) {
protected void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
}
}

View file

@ -38,14 +38,15 @@ import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.HasCustomInventoryScreen;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.entity.vehicle.ContainerEntity;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
@ -87,15 +88,12 @@ import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final float MAX_HEALTH = CannonConfig.SPEEDBOAT_HP.get();
public static final float MAX_ENERGY = CannonConfig.SPEEDBOAT_MAX_ENERGY.get().floatValue();
public static final int MAX_ENERGY = CannonConfig.SPEEDBOAT_MAX_ENERGY.get();
public static final int CONTAINER_SIZE = 105;
private NonNullList<ItemStack> items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY);
@ -123,35 +121,24 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(POWER, 0f);
this.entityData.define(AMMO, 0);
this.entityData.define(FIRE_ANIM, 0);
this.entityData.define(HEALTH, MAX_HEALTH);
this.entityData.define(ENERGY, 0f);
this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(HEAT, 0);
this.entityData.define(LAST_ATTACKER_UUID, "undefined");
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
compound.putFloat("Health", this.entityData.get(HEALTH));
super.addAdditionalSaveData(compound);
compound.putFloat("Energy", this.entityData.get(ENERGY));
compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID));
ContainerHelper.saveAllItems(compound, this.getItemStacks());
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(ENERGY, compound.getFloat("Energy"));
if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health"));
} else {
this.entityData.set(HEALTH, MAX_HEALTH);
}
if (compound.contains("LastAttacker")) {
this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker"));
}
super.readAdditionalSaveData(compound);
ContainerHelper.loadAllItems(compound, this.getItemStacks());
}
@ -175,44 +162,24 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
@Override
public boolean hurt(DamageSource source, float amount) {
super.hurt(source, amount);
if (this.level() instanceof ServerLevel serverLevel) {
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
}
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.LIGHTNING_BOLT))
return false;
if (source.is(DamageTypes.FALLING_ANVIL))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
amount *= 2f;
}
if (source.is(ModDamageTypes.CANNON_FIRE)) {
amount *= 3f;
}
if (source.is(ModDamageTypes.GUN_FIRE)) {
amount *= 0.3f;
}
if (source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE)) {
amount *= 1.2f;
amount *= 0.7f;
}
if (source.getEntity() != null) {
this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID());
}
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - 0.5f * Math.max(amount - 3, 0));
this.hurt(0.5f * Math.max(amount - 3, 0));
return true;
}
@ -235,8 +202,8 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
}
} else {
if (player.getMainHandItem().is(Items.IRON_INGOT)) {
if (this.entityData.get(HEALTH) < MAX_HEALTH) {
this.entityData.set(HEALTH, Math.min(this.entityData.get(HEALTH) + 0.1f * MAX_HEALTH, MAX_HEALTH));
if (this.getHealth() < this.getMaxHealth()) {
this.heal(Math.min(0.1f * this.getMaxHealth(), this.getMaxHealth()));
player.getMainHandItem().shrink(1);
if (!this.level().isClientSide) {
this.level().playSound(null, this, SoundEvents.IRON_GOLEM_REPAIR, this.getSoundSource(), 1, 1);
@ -308,12 +275,7 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f));
}
this.entityData.set(HEALTH, java.lang.Math.min(this.entityData.get(HEALTH) + 0.05f, MAX_HEALTH));
if (this.entityData.get(HEALTH) <= 0) {
this.ejectPassengers();
destroy();
}
this.heal(0.05f);
if (this.level() instanceof ServerLevel serverLevel && this.isInWater() && this.getDeltaMovement().length() > 0.1) {
sendParticle(serverLevel, ParticleTypes.CLOUD, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int)(2 + 4 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
@ -321,7 +283,6 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() - 4.5 * this.getLookAngle().x, this.getY() - 0.25, this.getZ() - 4.5 * this.getLookAngle().z, (int)(40 * Mth.abs(power)), 0.15, 0.15, 0.15, 0.02, true);
}
controlBoat();
collideBlock();
gunnerAngle();
pickUpItem();
@ -433,10 +394,11 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
});
}
private void controlBoat() {
@Override
public void travel() {
Entity passenger0 = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
if (this.entityData.get(ENERGY) <= 0) return;
if (this.getEnergy() <= 0) return;
if (passenger0 == null) {
this.leftInputDown = false;
@ -465,7 +427,7 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
}
if (this.forwardInputDown || this.backInputDown) {
this.entityData.set(ENERGY, Math.max(this.entityData.get(ENERGY) - CannonConfig.SPEEDBOAT_ENERGY_COST.get().floatValue(), 0));
this.extraEnergy(CannonConfig.SPEEDBOAT_ENERGY_COST.get());
}
if (level().isClientSide) {
@ -571,11 +533,12 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
}
}
}
private void destroy() {
@Override
public void destroy() {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), attacker,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 45f,
this.getX(), this.getY(), this.getZ(), 3f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 75f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
@ -620,16 +583,6 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
return this.cache;
}
@Override
public void charge(int amount) {
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, MAX_ENERGY));
}
@Override
public boolean canCharge() {
return this.entityData.get(ENERGY) < MAX_ENERGY;
}
@Override
protected boolean canAddPassenger(Entity pPassenger) {
return this.getPassengers().size() < this.getMaxPassengers();
@ -772,24 +725,14 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
this.level().gameEvent(GameEvent.CONTAINER_CLOSE, this.position(), GameEvent.Context.of(pPlayer));
}
@Override
public int getEnergy() {
return this.entityData.get(ENERGY).intValue();
}
@Override
public int getMaxEnergy() {
return (int) MAX_ENERGY;
}
@Override
public float getHealth() {
return this.entityData.get(HEALTH).intValue();
return MAX_ENERGY;
}
@Override
public float getMaxHealth() {
return (int) MAX_HEALTH;
return MAX_HEALTH;
}
@Override

View file

@ -0,0 +1,188 @@
package com.atsuishio.superbwarfare.entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.joml.Math;
public class VehicleEntity extends Entity {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.STRING);
protected int interpolationSteps;
protected double x;
protected double y;
protected double z;
protected double serverYRot;
protected double serverXRot;
public VehicleEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
this.setHealth(this.getMaxHealth());
}
@Override
protected void defineSynchedData() {
this.entityData.define(HEALTH, this.getMaxHealth());
this.entityData.define(LAST_ATTACKER_UUID, "undefined");
}
@Override
protected void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker"));
this.entityData.set(HEALTH, compound.getFloat("Health"));
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
compound.putFloat("Health", this.entityData.get(HEALTH));
compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID));
}
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.LIGHTNING_BOLT))
return false;
if (source.is(DamageTypes.FALLING_ANVIL))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.getEntity() != null) {
this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID());
}
return true;
}
public void heal(float pHealAmount) {
this.setHealth(this.getHealth() + pHealAmount);
}
public void hurt(float pHealAmount) {
this.setHealth(this.getHealth() - pHealAmount);
}
public float getHealth() {
return this.entityData.get(HEALTH);
}
public void setHealth(float pHealth) {
this.entityData.set(HEALTH, Mth.clamp(pHealth, 0.0F, this.getMaxHealth()));
}
public float getMaxHealth() {
return 50;
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean isPushable() {
return false;
}
@Override
public boolean isPickable() {
return !this.isRemoved();
}
@Override
public void baseTick() {
super.baseTick();
float delta = Math.abs(getYRot() - yRotO);
while (getYRot() > 180F) {
setYRot(getYRot() - 360F);
yRotO = getYRot() - delta;
}
while (getYRot() <= -180F) {
setYRot(getYRot() + 360F);
yRotO = delta + getYRot();
}
handleClientSync();
if (this.getHealth() <= 0) {
this.ejectPassengers();
destroy();
}
travel();
this.refreshDimensions();
}
public void destroy() {
}
public void travel() {
}
protected void handleClientSync() {
if (isControlledByLocalInstance()) {
interpolationSteps = 0;
syncPacketPositionCodec(getX(), getY(), getZ());
}
if (interpolationSteps <= 0) {
return;
}
double interpolatedX = getX() + (x - getX()) / (double) interpolationSteps;
double interpolatedY = getY() + (y - getY()) / (double) interpolationSteps;
double interpolatedZ = getZ() + (z - getZ()) / (double) interpolationSteps;
double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot());
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
setPos(interpolatedX, interpolatedY, interpolatedZ);
setRot(getYRot(), getXRot());
--interpolationSteps;
}
@Override
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
this.x = x;
this.y = y;
this.z = z;
serverYRot = yaw;
serverXRot = pitch;
this.interpolationSteps = 10;
}
public static double calculateAngle(Vec3 move, Vec3 view) {
move = move.multiply(1, 0, 1).normalize();
view = view.multiply(1, 0, 1).normalize();
double startLength = move.length();
double endLength = view.length();
if (startLength > 0.0D && endLength > 0.0D) {
return Math.toDegrees(Math.acos(Mth.clamp(move.dot(view) / (startLength * endLength), -1, 1)));
} else {
return 0.0D;
}
}
}

View file

@ -1,15 +1,17 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.syncher.EntityDataAccessor;
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.sounds.SoundEvents;
@ -18,12 +20,11 @@ import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
@ -33,13 +34,10 @@ import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, IVehicleEntity, IChargeEntity {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(WheelChairEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(WheelChairEntity.class, EntityDataSerializers.FLOAT);
public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, IVehicleEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = 50;
public static final float MAX_ENERGY = 24000;
public static final int MAX_ENERGY = 24000;
public float leftWheelRot;
public float rightWheelRot;
public float leftWheelRotO;
@ -56,23 +54,17 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
@Override
protected void defineSynchedData() {
this.entityData.define(HEALTH, MAX_HEALTH);
this.entityData.define(ENERGY, 0f);
super.defineSynchedData();
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health"));
} else {
this.entityData.set(HEALTH, MAX_HEALTH);
}
compound.putFloat("Energy", this.entityData.get(ENERGY));
super.addAdditionalSaveData(compound);
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(ENERGY, compound.getFloat("Energy"));
super.readAdditionalSaveData(compound);
}
@Override
@ -92,27 +84,9 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.LIGHTNING_BOLT))
return false;
if (source.is(DamageTypes.FALLING_ANVIL))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
super.hurt(source, amount);
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
this.hurt(amount);
return true;
}
@ -128,8 +102,8 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
this.discard();
} else {
if (player.getMainHandItem().is(Items.IRON_INGOT)) {
if (this.entityData.get(HEALTH) < MAX_HEALTH) {
this.entityData.set(HEALTH, Math.min(this.entityData.get(HEALTH) + 0.5f * MAX_HEALTH, MAX_HEALTH));
if (this.getHealth() < this.getMaxHealth()) {
this.heal(Math.min(0.5f * this.getMaxHealth(), this.getMaxHealth()));
player.getMainHandItem().shrink(1);
if (!this.level().isClientSide) {
this.level().playSound(null, this, SoundEvents.IRON_GOLEM_REPAIR, this.getSoundSource(), 1, 1);
@ -161,12 +135,12 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
this.move(MoverType.SELF, this.getDeltaMovement());
if (this.entityData.get(HEALTH) <= 0) {
if (this.getHealth() <= 0) {
this.ejectPassengers();
destroy();
}
if (level().isClientSide && this.entityData.get(ENERGY) > 0) {
if (level().isClientSide && this.getEnergy() > 0) {
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), ModSounds.WHEEL_CHAIR_ENGINE.get(), this.getSoundSource(), (float) (0.2 * this.getDeltaMovement().length()), (random.nextFloat() * 0.1f + 0.7f), false);
}
@ -176,38 +150,46 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
this.refreshDimensions();
}
@Override
public void travel() {
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
if (!(passenger instanceof LivingEntity entity)) return;
float diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(entity.getYHeadRot() - this.getYRot()));
float diffY = 0;
this.setYRot(this.getYRot() + Mth.clamp(0.4f * diffY,-5f, 5f));
if (passenger == null) {
this.leftInputDown = false;
this.rightInputDown = false;
this.forwardInputDown = false;
this.backInputDown = false;
} else {
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
this.setYRot(this.getYRot() + Mth.clamp(0.4f * diffY, -5f, 5f));
}
if (this.forwardInputDown) {
power += 0.01f;
if (this.entityData.get(ENERGY) <= 0 && entity instanceof Player player) {
if (this.getEnergy() <= 0 && passenger instanceof Player player) {
moveWithOutPower(player, true);
}
}
if (this.backInputDown) {
power -= 0.01f;
if (this.entityData.get(ENERGY) <= 0 && entity instanceof Player player) {
if (this.getEnergy() <= 0 && passenger instanceof Player player) {
moveWithOutPower(player, false);
}
}
if (this.upInputDown && this.onGround() && this.entityData.get(ENERGY) > 800) {
if (entity instanceof ServerPlayer serverPlayer) {
if (this.upInputDown && this.onGround() && this.getEnergy() > 400) {
if (passenger instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.WHEEL_CHAIR_JUMP.get(), SoundSource.PLAYERS, 1, 1);
}
this.entityData.set(ENERGY, this.entityData.get(ENERGY) - 800);
this.extraEnergy(400);
this.setDeltaMovement(this.getDeltaMovement().add(0, 0.58, 0));
}
if (this.forwardInputDown || this.backInputDown) {
this.entityData.set(ENERGY, Math.max(this.entityData.get(ENERGY) - 1, 0));
this.extraEnergy(1);
}
power *= 0.87f;
@ -221,8 +203,8 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
s0 = -this.getDeltaMovement().length();
}
this.setLeftWheelRot((float) (this.getLeftWheelRot() - 0.85 * s0) - 0.015f * Mth.clamp(0.4f * diffY,-5f, 5f));
this.setRightWheelRot((float) (this.getRightWheelRot() - 0.85 * s0) + 0.015f * Mth.clamp(0.4f * diffY,-5f, 5f));
this.setLeftWheelRot((float) (this.getLeftWheelRot() - 1 * s0) - 0.015f * Mth.clamp(0.4f * diffY, -5f, 5f));
this.setRightWheelRot((float) (this.getRightWheelRot() - 1 * s0) + 0.015f * Mth.clamp(0.4f * diffY, -5f, 5f));
// if (entity instanceof Player player) {
// player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.##").format(this.getRightWheelRot())), true);
@ -274,11 +256,19 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
this.clampRotation(entity);
}
private void destroy() {
@Override
public void destroy() {
if (level() instanceof ServerLevel) {
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 25.0f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.discard();
}
this.discard();
}
@Override
@ -294,14 +284,9 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
return this.cache;
}
@Override
public float getHealth() {
return this.entityData.get(HEALTH).intValue();
}
@Override
public float getMaxHealth() {
return (int) MAX_HEALTH;
return MAX_HEALTH;
}
@Override
@ -324,23 +309,8 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
return -1;
}
@Override
public int getEnergy() {
return this.entityData.get(ENERGY).intValue();
}
@Override
public int getMaxEnergy() {
return (int) MAX_ENERGY;
}
@Override
public void charge(int amount) {
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, MAX_ENERGY));
}
@Override
public boolean canCharge() {
return this.entityData.get(ENERGY) < MAX_ENERGY;
return MAX_ENERGY;
}
}