Jump to content

[1.19.2]Crash on creating entity


JuSTGh0sT1242

Recommended Posts

So basically, I trying to create a "Smoke Bomb", and for that I made Item that throwing a smoke bomb projectile, and after smoke bomb projectile is hit block, it should create entity "smoke zone" but instead of that I got immediately crashed. I can't even make a renderer for this entity in mod class, it give an error, and I honestly don't know WHERE and WHY.

public class SmokeBombEntity extends ThrowableItemProjectile {
    public  SmokeBombEntity(EntityType<? extends ThrowableItemProjectile> pEntityType, Level pLevel) {

        super(pEntityType, pLevel);
    }
public  SmokeBombEntity(Level pLevel) {
        super(ModEntities.SMOKE_BOMB_PROJECTILE.get(), pLevel);
    }
public  SmokeBombEntity(Level pLevel, LivingEntity livingEntity) {
        super(ModEntities.SMOKE_BOMB_PROJECTILE.get(), livingEntity, pLevel);
    }
    @Override
    protected Item getDefaultItem() {
        return ModItems.SMOKE_BOMB.get();
    }

    @Override
    protected void onHitBlock(BlockHitResult pResult) {
        if(!this.level.isClientSide) {
            SmokeZoneEntity smokeZone = new SmokeZoneEntity(ModEntities.SMOKE_ZONE_ENTITY.get(), level);
            smokeZone.setPos(getBlockX(),getBlockY(),getBlockZ());
            this.level.addFreshEntity(smokeZone);
        }
        level.playSound((Player) null, getBlockX(), getBlockY(), getBlockZ(), SoundEvents.GLASS_BREAK, SoundSource.NEUTRAL, 0.5F, 0.4F);
        this.discard();
        super.onHitBlock(pResult);
    }
}
public class SmokeZoneEntity extends Entity {
    public SmokeZoneEntity(EntityType<?> pEntityType, Level pLevel) {
        super(pEntityType, pLevel);
        this.noPhysics = true;
    }
    public SmokeZoneEntity(Level pLevel, double pX, double pY, double pZ) {
        this(ModEntities.SMOKE_ZONE_ENTITY.get(), pLevel);
        this.setPos(pX, pY, pZ);
    }
    public  SmokeZoneEntity(Level pLevel) {
        super(ModEntities.SMOKE_ZONE_ENTITY.get(), pLevel);
    }



    protected void defineSynchedData() {}
    protected void readAdditionalSaveData(CompoundTag pCompound) {}
    protected void addAdditionalSaveData(CompoundTag pCompound) {

    }
    public Packet<?> getAddEntityPacket() {
        return new ClientboundAddEntityPacket(this);
    }
}

Also I can't render a smoke zone entity in a mod class, but smoke bomb projectile works completely fine

 @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event) {

            EntityRenderers.register(ModEntities.SMOKE_BOMB_PROJECTILE.get(), ThrownItemRenderer::new);
          //HERE AN ISSUE  EntityRenderers.register(ModEntities.SMOKE_ZONE_ENTITY.get(), EntityRenderer::new);

        }
    }
}

GitHub repository
 

Edited by JuSTGh0sT1242
added code for context
Link to comment
Share on other sites

  • JuSTGh0sT1242 changed the title to [1.19.2]Crash on creating entity

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.



×
×
  • Create New...

Important Information

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