diff --git a/src/main/java/fathertoast/specialmobs/common/core/register/SMEntities.java b/src/main/java/fathertoast/specialmobs/common/core/register/SMEntities.java index 9e3e246..ff63b3c 100644 --- a/src/main/java/fathertoast/specialmobs/common/core/register/SMEntities.java +++ b/src/main/java/fathertoast/specialmobs/common/core/register/SMEntities.java @@ -3,7 +3,7 @@ package fathertoast.specialmobs.common.core.register; import fathertoast.specialmobs.common.bestiary.MobFamily; import fathertoast.specialmobs.common.config.util.ConfigDrivenAttributeModifierMap; import fathertoast.specialmobs.common.core.SpecialMobs; -import fathertoast.specialmobs.common.entity.projectile.CorporealShiftFireballEntity; +import fathertoast.specialmobs.common.entity.projectile.IncorporealFireballEntity; import fathertoast.specialmobs.common.util.AnnotationHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityClassification; @@ -18,8 +18,8 @@ public class SMEntities { public static final DeferredRegister> REGISTRY = DeferredRegister.create( ForgeRegistries.ENTITIES, SpecialMobs.MOD_ID ); // Misc entities - public static final RegistryObject> CORPOREAL_FIREBALL = register( "corporeal_shift_fireball", - EntityType.Builder.of( CorporealShiftFireballEntity::new, EntityClassification.MISC ).sized( 1.0F, 1.0F ).clientTrackingRange( 4 ).updateInterval( 3 ) ); + public static final RegistryObject> CORPOREAL_FIREBALL = register( "incorporeal_fireball", + EntityType.Builder.of( IncorporealFireballEntity::new, EntityClassification.MISC ).sized( 1.0F, 1.0F ).clientTrackingRange( 4 ).updateInterval( 3 ) ); /** Registers an entity type to the deferred register. */ public static RegistryObject> register( String name, EntityType.Builder builder ) { diff --git a/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java index 57c3af1..8cc1360 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java @@ -4,12 +4,14 @@ import fathertoast.specialmobs.common.bestiary.BestiaryInfo; import fathertoast.specialmobs.common.bestiary.MobFamily; import fathertoast.specialmobs.common.bestiary.SpecialMob; import fathertoast.specialmobs.common.core.register.SMItems; -import fathertoast.specialmobs.common.entity.projectile.CorporealShiftFireballEntity; +import fathertoast.specialmobs.common.entity.projectile.IncorporealFireballEntity; import fathertoast.specialmobs.common.util.References; import fathertoast.specialmobs.datagen.loot.LootTableBuilder; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.Attributes; +import net.minecraft.entity.projectile.FireballEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; @@ -90,7 +92,18 @@ public class CorporealShiftGhastEntity extends _SpecialGhastEntity { private void spawnShiftSmoke( ServerWorld world ) { world.sendParticles( ParticleTypes.CLOUD, this.getX(), this.getY(), this.getZ(), 25, 0.0, 0.0, 0.0, 0.4 ); } - + + @Override + public boolean isPushable() { + return isCorporeal() && super.isPushable(); + } + + @Override + protected void doPush(Entity entity) { + if (isCorporeal()) + super.doPush(entity); + } + public boolean isCorporeal() { return entityData.get( CORPOREAL ); } private void setCorporeal( boolean value ) { entityData.set( CORPOREAL, value ); } @@ -109,14 +122,25 @@ public class CorporealShiftGhastEntity extends _SpecialGhastEntity { double dX = target.getX() - (getX() + lookVec.x) + getRandom().nextGaussian() * accelVariance; double dY = target.getY( 0.5 ) - (0.5 + getY( 0.5 )); double dZ = target.getZ() - (getZ() + lookVec.z) + getRandom().nextGaussian() * accelVariance; - - final CorporealShiftFireballEntity fireball = new CorporealShiftFireballEntity( level, this, dX, dY, dZ ); - fireball.explosionPower = getVariantExplosionPower( getExplosionPower() ); - fireball.setPos( - getX() + lookVec.x, - getY( 0.5 ) + 0.5, - getZ() + lookVec.z ); - level.addFreshEntity( fireball ); + + if (isCorporeal()) { + FireballEntity fireball = new FireballEntity( level, this, dX, dY, dZ ); + fireball.explosionPower = getVariantExplosionPower( getExplosionPower() ); + fireball.setPos( + getX() + lookVec.x, + getY( 0.5 ) + 0.5, + getZ() + lookVec.z ); + level.addFreshEntity( fireball ); + } + else { + IncorporealFireballEntity fireball = new IncorporealFireballEntity( level, this, dX, dY, dZ ); + fireball.explosionPower = getVariantExplosionPower( getExplosionPower() ); + fireball.setPos( + getX() + lookVec.x, + getY( 0.5 ) + 0.5, + getZ() + lookVec.z ); + level.addFreshEntity( fireball ); + } } diff --git a/src/main/java/fathertoast/specialmobs/common/entity/projectile/CorporealShiftFireballEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/projectile/IncorporealFireballEntity.java similarity index 59% rename from src/main/java/fathertoast/specialmobs/common/entity/projectile/CorporealShiftFireballEntity.java rename to src/main/java/fathertoast/specialmobs/common/entity/projectile/IncorporealFireballEntity.java index e107a3c..733309f 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/projectile/CorporealShiftFireballEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/projectile/IncorporealFireballEntity.java @@ -1,7 +1,6 @@ package fathertoast.specialmobs.common.entity.projectile; import fathertoast.specialmobs.common.bestiary.SpecialMob; -import fathertoast.specialmobs.common.core.SpecialMobs; import fathertoast.specialmobs.common.core.register.SMEntities; import fathertoast.specialmobs.common.core.register.SMItems; import fathertoast.specialmobs.common.entity.ghast.CorporealShiftGhastEntity; @@ -12,12 +11,8 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.AbstractFireballEntity; import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.IPacket; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.network.datasync.DataSerializers; -import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.DamageSource; import net.minecraft.util.SoundEvents; import net.minecraft.util.math.EntityRayTraceResult; @@ -25,16 +20,16 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.Explosion; import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.util.Constants; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.fml.network.NetworkHooks; import javax.annotation.Nullable; -public class CorporealShiftFireballEntity extends AbstractFireballEntity { - - private static final DataParameter CORPOREAL = EntityDataManager.defineId( CorporealShiftFireballEntity.class, DataSerializers.BOOLEAN ); - +public class IncorporealFireballEntity extends AbstractFireballEntity { + public int explosionPower = 1; private boolean shouldExplode = false; @@ -42,49 +37,31 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { private LivingEntity target; - public CorporealShiftFireballEntity( EntityType entityType, World world ) { + public IncorporealFireballEntity(EntityType entityType, World world ) { super( entityType, world ); } - public CorporealShiftFireballEntity( World world, CorporealShiftGhastEntity ghast, double x, double y, double z ) { + public IncorporealFireballEntity(World world, CorporealShiftGhastEntity ghast, double x, double y, double z ) { super( SMEntities.CORPOREAL_FIREBALL.get(), ghast, x, y, z, world ); - setCorporeal( ghast.isCorporeal() ); target = ghast.getTarget(); - setItem( isCorporeal() ? new ItemStack( Items.FIRE_CHARGE ) : new ItemStack( SMItems.INCORPOREAL_FIREBALL.get() ) ); } - public CorporealShiftFireballEntity( World world, PlayerEntity owner, LivingEntity target, double x, double y, double z ) { + public IncorporealFireballEntity(World world, PlayerEntity owner, LivingEntity target, double x, double y, double z ) { super( SMEntities.CORPOREAL_FIREBALL.get(), owner, x, y, z, world ); - setCorporeal( false ); this.target = target; - setItem( new ItemStack( SMItems.INCORPOREAL_FIREBALL.get() ) ); } @SpecialMob.LanguageProvider public static String[] getTranslations( String langKey ) { - return References.translations( langKey, "Corporeal Shift Fireball", + return References.translations( langKey, "Incorporeal Fireball", "", "", "", "", "", "" );//TODO } - @Override - protected void defineSynchedData() { - super.defineSynchedData(); - entityData.define( CORPOREAL, true ); - } - - public boolean isCorporeal() { - return entityData.get( CORPOREAL ); - } - - public void setCorporeal( boolean corporeal ) { - entityData.set( CORPOREAL, corporeal ); - } - @Override public void tick() { super.tick(); - if( !level.isClientSide && !isCorporeal() ) { + if( !level.isClientSide ) { // Fizzle out and die when the target is dead or lost, // or else the fireball goes bonkers. if( target == null || !target.isAlive() ) { @@ -112,19 +89,12 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { @Override protected boolean shouldBurn() { - // Hee hee hee haw - return isCorporeal(); + return false; } @Override protected void onHit( RayTraceResult traceResult ) { super.onHit( traceResult ); - - // Only go boom if the fireball is corporeal. - // If not, pass through blocks to be a menace. - if( !level.isClientSide && isCorporeal() ) { - shouldExplode = true; - } } @Override @@ -133,52 +103,45 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { if( !this.level.isClientSide ) { Entity target = traceResult.getEntity(); - Entity owner = getOwner(); - - if( !isCorporeal() ) { - // TODO - Figure out why this is cringe - // TODO part 2. - What the fuck - // TODO part 3. - HELP - SpecialMobs.LOG.info( "X={}, XO={}", target.getX(), target.xo ); - SpecialMobs.LOG.info( "Z={}, ZO={}", target.getZ(), target.zo ); - - if( target.getX() != target.xo || target.getY() != target.yo || target.getZ() != target.zo ) { - explode(); - } - else { - playSound( SoundEvents.FIRE_EXTINGUISH, 1.0F, 1.0F ); - remove(); - } + + boolean fizzle; + + if ( target instanceof PlayerEntity ) { + // TODO - Implement player-specific checks + fizzle = true; } else { - target.hurt( DamageSource.fireball( this, owner ), 6.0F ); - - if( owner instanceof LivingEntity ) { - doEnchantDamageEffects( (LivingEntity) owner, target ); + if (target.getX() != target.xo || target.getY() != target.yo || target.getZ() != target.zo) { + explode(); + return; } + fizzle = true; + } + if (fizzle) { + playSound( SoundEvents.FIRE_EXTINGUISH, 1.0F, 1.0F ); + remove(); } } } @Override public boolean hurt( DamageSource damageSource, float damage ) { - if( !isCorporeal() ) { - if( isInvulnerableTo( damageSource ) || damageSource.isFire() ) { - return false; - } - shouldExplode = true; - return true; - } - else { - return super.hurt( damageSource, damage ); + if( isInvulnerableTo( damageSource ) || damageSource.isFire() ) { + return false; } + shouldExplode = true; + return true; + } + + @OnlyIn(Dist.CLIENT) + public ItemStack getItem() { + return new ItemStack(SMItems.INCORPOREAL_FIREBALL.get()); } @Override public void addAdditionalSaveData( CompoundNBT compoundNBT ) { super.addAdditionalSaveData( compoundNBT ); compoundNBT.putInt( "ExplosionPower", explosionPower ); - compoundNBT.putBoolean( "Corporeal", isCorporeal() ); compoundNBT.putInt( "TargetId", target == null ? -1 : target.getId() ); } @@ -188,7 +151,6 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { if( compoundNBT.contains( "ExplosionPower", Constants.NBT.TAG_ANY_NUMERIC ) ) { explosionPower = compoundNBT.getInt( "ExplosionPower" ); } - entityData.set( CORPOREAL, compoundNBT.getBoolean( "Corporeal" ) ); if( compoundNBT.contains( "TargetId", Constants.NBT.TAG_ANY_NUMERIC ) ) { Entity entity = level.getEntity( compoundNBT.getInt( "TargetId" ) ); diff --git a/src/main/java/fathertoast/specialmobs/common/network/work/ServerWork.java b/src/main/java/fathertoast/specialmobs/common/network/work/ServerWork.java index b15773f..cca5778 100644 --- a/src/main/java/fathertoast/specialmobs/common/network/work/ServerWork.java +++ b/src/main/java/fathertoast/specialmobs/common/network/work/ServerWork.java @@ -1,6 +1,6 @@ package fathertoast.specialmobs.common.network.work; -import fathertoast.specialmobs.common.entity.projectile.CorporealShiftFireballEntity; +import fathertoast.specialmobs.common.entity.projectile.IncorporealFireballEntity; import fathertoast.specialmobs.common.network.message.C2SSpawnIncorporealFireball; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -30,7 +30,7 @@ public class ServerWork { return; LivingEntity livingEntity = (LivingEntity) entity; - CorporealShiftFireballEntity fireballEntity = new CorporealShiftFireballEntity(world, player, livingEntity, player.getX(), player.getEyeY(), player.getZ()); + IncorporealFireballEntity fireballEntity = new IncorporealFireballEntity(world, player, livingEntity, player.getX(), player.getEyeY(), player.getZ()); world.addFreshEntity(fireballEntity); } }