Jump to content

[1.16.1] Custom Projectile not working (creating an EntityType)


Recommended Posts

Posted

Hi all, for my mod I am making a spider that shoots poisonous projectiles at the player (called a crawler) and I want to make a custom projectile for this. I have made the projectile entity class and I know that I need to make the rendering class, but before I do that I need to make a custom EntityType in order to even create the projectile entity in the world. Here is my projectile class:

public class CrawlerVenomEntity extends AbstractCrawlerVenomEntity {
    public int explosionPower = 0;
    public double explosionRadius = 2.0;

    public CrawlerVenomEntity(EntityType<CrawlerVenomEntity> type, World worldIn) {
        super(type, worldIn);
    }

    @OnlyIn(Dist.CLIENT)
    public CrawlerVenomEntity(EntityType<? extends CrawlerVenomEntity> type, World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ) {
        super(type, x, y, z, accelX, accelY, accelZ, worldIn);
        this.setVelocity(accelX, accelY, accelZ);
    }

    /**
     * Called when this EntityFireball hits a block or entity.
     */
    protected void onImpact(RayTraceResult result) {
        super.onImpact(result);
        if (!this.world.isRemote) {
            boolean flag = net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.func_234616_v_());
            this.world.playSound(this.getPosX(),this.getPosY(),this.getPosZ(), SoundEvents.ENTITY_SPIDER_AMBIENT, SoundCategory.HOSTILE,1.0F,1.0F,true);
            World world = this.getEntityWorld();
            world.addParticle(ParticleTypes.ITEM_SLIME,this.getPosX(),this.getPosY()+0.5,this.getPosZ(),0,1,0);
            world.addParticle(ParticleTypes.ITEM_SLIME,this.getPosX(),this.getPosY()+1.5,this.getPosZ(),0,1,0);
            world.addParticle(ParticleTypes.ITEM_SLIME,this.getPosX(),this.getPosY()+1.0,this.getPosZ(),0,1,0);

            // this.world.createExplosion((Entity)null, this.getPosX(), this.getPosY(), this.getPosZ(), (float)this.explosionPower, flag, flag ? Explosion.Mode.DESTROY : Explosion.Mode.NONE);
            Vector3d victor = result.getHitVec();
            AxisAlignedBB aabb = new AxisAlignedBB(this.getPosX()-explosionRadius,this.getPosY()-explosionRadius,this.getPosZ()-explosionRadius,
                    this.getPosX()+explosionRadius,this.getPosY()+explosionRadius,this.getPosZ()+explosionRadius);
            for(LivingEntity e:this.world.getEntitiesWithinAABB(LivingEntity.class,aabb)) {
                e.attackEntityFrom(DamageSource.MAGIC,5);
                e.addPotionEffect(new EffectInstance(Effects.POISON,80,1));
            }
            this.remove();
        }

    }

    /**
     * Called when the arrow hits an entity
     */
    protected void onEntityHit(EntityRayTraceResult p_213868_1_) {
        super.onEntityHit(p_213868_1_);
        if (!this.world.isRemote) {
            Entity entity = p_213868_1_.getEntity();
            Entity entity1 = this.func_234616_v_();
            entity.attackEntityFrom(DamageSource.MAGIC, 6.0F);
            if (entity1 instanceof LivingEntity) {
                this.applyEnchantments((LivingEntity)entity1, entity);
            }

        }
    }

    public void writeAdditional(CompoundNBT compound) {
        super.writeAdditional(compound);
        compound.putInt("ExplosionPower", this.explosionPower);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readAdditional(CompoundNBT compound) {
        super.readAdditional(compound);
        if (compound.contains("ExplosionPower", 99)) {
            this.explosionPower = compound.getInt("ExplosionPower");
        }

    }

    protected ItemStack getStack() {
        return new ItemStack(Items.SLIME_BALL);
    }

    @OnlyIn(Dist.CLIENT)
    public ItemStack getItem() {
        ItemStack itemstack = this.getStack();
        return itemstack.isEmpty() ? new ItemStack(Items.SLIME_BALL) : itemstack;
    }

}

Here is the AbstractCrawlerVenomEntity class:

@OnlyIn(
        value = Dist.CLIENT,
        _interface = IRendersAsItem.class
)
public abstract class AbstractCrawlerVenomEntity extends DamagingProjectileEntity implements IRendersAsItem {
    private static final DataParameter<ItemStack> STACK = EntityDataManager.createKey(net.minecraft.entity.projectile.AbstractFireballEntity.class, DataSerializers.ITEMSTACK);

    public AbstractCrawlerVenomEntity(EntityType<? extends AbstractCrawlerVenomEntity> p_i50166_1_, World p_i50166_2_) {
        super(p_i50166_1_, p_i50166_2_);
    }

    public AbstractCrawlerVenomEntity(EntityType<? extends AbstractCrawlerVenomEntity> p_i50167_1_, double p_i50167_2_, double p_i50167_4_, double p_i50167_6_, double p_i50167_8_, double p_i50167_10_, double p_i50167_12_, World p_i50167_14_) {
        super(p_i50167_1_, p_i50167_2_, p_i50167_4_, p_i50167_6_, p_i50167_8_, p_i50167_10_, p_i50167_12_, p_i50167_14_);
    }

    public void setStack(ItemStack p_213898_1_) {
        if (p_213898_1_.getItem() != Items.FIRE_CHARGE || p_213898_1_.hasTag()) {
            this.getDataManager().set(STACK, Util.make(p_213898_1_.copy(), (p_213897_0_) -> {
                p_213897_0_.setCount(1);
            }));
        }

    }

    protected ItemStack getStack() {
        return this.getDataManager().get(STACK);
    }

    @OnlyIn(Dist.CLIENT)
    public ItemStack getItem() {
        ItemStack itemstack = this.getStack();
        return itemstack.isEmpty() ? new ItemStack(Items.FIRE_CHARGE) : itemstack;
    }

    protected void registerData() {
        this.getDataManager().register(STACK, ItemStack.EMPTY);
    }

    public void writeAdditional(CompoundNBT compound) {
        super.writeAdditional(compound);
        ItemStack itemstack = this.getStack();
        if (!itemstack.isEmpty()) {
            compound.put("Item", itemstack.write(new CompoundNBT()));
        }

    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readAdditional(CompoundNBT compound) {
        super.readAdditional(compound);
        ItemStack itemstack = ItemStack.read(compound.getCompound("Item"));
        this.setStack(itemstack);
    }
}

And I am trying to create an EntityType for this class so I can spawn it in by doing the following in my EntityTypesInit:

public class ModEntityTypes {

    public static DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, MajCraft.MOD_ID);

    // All my other Entity Types here

    // Projectile Entity Types
      public static final RegistryObject<EntityType<CrawlerVenomEntity>> CRAWLER_VENOM = ENTITY_TYPES.register("crawler_venom",
            () -> EntityType.Builder.create(CrawlerVenomEntity::new, EntityClassification.MISC)
                    .size(1.0f,0.5f)
                    .build(new ResourceLocation(MajCraft.MOD_ID, "crawler_venom").toString())
    );

}

But for some reason it does not like the CrawlerVenomEntity::new and I do not know why... I've played around with changing the data types of the parameters.

To spawn in the entity I want to do something like this: 

CrawlerVenomEntity test = new CrawlerVenomEntity(ModEntityTypes.CRAWLER_VENOM,worldIn,playerIn.getPosX()+playerIn.getForward().getX(),playerIn.getPosY()+1.25,playerIn.getPosZ()+playerIn.getForward().getZ(),playerIn.getForward().getX(),playerIn.getForward().getY(),playerIn.getForward().getZ())

 

Why isn't this working? Thank you for your time!

Posted (edited)
      public static final RegistryObject<EntityType<CrawlerVenomEntity>> CRAWLER_VENOM = ENTITY_TYPES.register("crawler_venom",
            () -> EntityType.Builder.<CrawlerVenomEntity> <----- create(CrawlerVenomEntity::new, EntityClassification.MISC)
                    .size(1.0f,0.5f)
                    .build(new ResourceLocation(MajCraft.MOD_ID, "crawler_venom").toString())
    );

https://www.tutorialspoint.com/java/java_generics.htm

Edited by poopoodice

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.