Jump to content

[SOLVED][1.15.2] Custom Entity Spawning on Server but not Client?


Woodside

Recommended Posts

My custom entity:

public class BeamAttackEntity extends Entity {
    private Vec3d to;
    private int lifeTicksRemaining;
    private Entity sourceEntity;

    public BeamAttackEntity(EntityType<? extends BeamAttackEntity> entityType, World world) {
        super(entityType, world);
    }

    public BeamAttackEntity(Vec3d from, Vec3d to, int lifeTicks, World world) {
        super(ModEntityTypes.BEAM_ATTACK.get(), world);
        this.setPosition(from.x, from.y, from.z);
        this.to = to;
        this.lifeTicksRemaining = lifeTicks;
        this.sourceEntity = null;
    }

    public BeamAttackEntity(Entity sourceEntity, Vec3d to, int lifeTicks, World world) {
        super(ModEntityTypes.BEAM_ATTACK.get(), world);
        Vec3d entityPos = sourceEntity.getPositionVec();
        this.setPosition(entityPos.x, entityPos.y, entityPos.z);
        this.to = to;
        this.lifeTicksRemaining = lifeTicks;
    }

    @Override
    protected void registerData() {

    }

    @Override
    protected void readAdditional(CompoundNBT compound) {

    }

    @Override
    protected void writeAdditional(CompoundNBT compound) {
        final CompoundNBT beamData = new CompoundNBT();


    }

    @Override
    public IPacket<?> createSpawnPacket() {
        return new SSpawnObjectPacket(this);
    }

    @Override
    public void tick() {
        CelticShift.LOGGER.info("in entity {}", this.lifeTicksRemaining);
        if (this.lifeTicksRemaining > 0) {
            this.lifeTicksRemaining--;
        } else {
            this.remove();
        }
    }

    public int getLifeTicksRemaining() {
        return this.lifeTicksRemaining;
    }
}

 

Deferred registry:

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

public static final RegistryObject<EntityType<BeamAttackEntity>> BEAM_ATTACK = ENTITY_TYPES.register("beam_attack",
            () -> EntityType.Builder.<BeamAttackEntity>create(BeamAttackEntity::new, EntityClassification.MISC)
                    .size(0.5f, 0.5f)
                    .build(new ResourceLocation(CelticShift.MOD_ID, "beam_attack").toString()));

 

Context in which I'm spawning it (in the AI goal for another, functional entity -- modeled after how the Ghast spawns fireballs):

BeamAttackEntity beamAttackEntity = new BeamAttackEntity(this.subject, this.subject.getPositionVec().add(10, 0, 10), 30, world);
world.addEntity(beamAttackEntity);

 

What I am observing is that the logger message in the entity class prints out for the server, but not the client. There's also no evidence (using dev tools, since I do not have a renderer set up yet) that the entity is coming client side at all.

Am I missing a step somewhere?

Edited by Woodside
solved
Link to comment
Share on other sites

18 minutes ago, Curle said:

The Spawn Packet must be made with the static function in NetworkHooks, do not use the vanilla packet. 

That should solve the problem.

 

19 minutes ago, diesieben07 said:

SSpawnObjectPacket only works for vanilla entities. You have to use NetworkHooks.getEntitySpawningPacket.

 

Grand. Thank you both!

Link to comment
Share on other sites

  • Woodside changed the title to [SOLVED][1.15.2] Custom Entity Spawning on Server but not Client?

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.