Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

That should solve the problem.

  • Author
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!

  • 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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.