Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved] Rendering ProjectileItemEntity 1.16.5


Recommended Posts

Привет. Сразу прошу прощения за мой английский, я не носитель этого языка.

Пытаюсь создать гранату. Но возникли проблемы с отрисовкой моего ProjectileItemEntity.

Доходит до моба, но в игре не отображается.
Прочитал некоторые темы, но так и не понял, что нужно делать на версии 1.16.5

GranateEntity.java

   

       
    

       
    

    public GranateEntity(double x, double y, double z, World world) {
        super(Registration.granateEntity.get(), x, y, z, world);
    }

    @OnlyIn(Dist.CLIENT)
    public void handleEntityEvent(byte p_70103_1_) {
        if (p_70103_1_ == 3) {
            double d0 = 0.08D;

            for(int i = 0; i < 8; ++i) {
                this.level.addParticle(new ItemParticleData(ParticleTypes.ITEM, this.getItem()), this.getX(), this.getY(), this.getZ(), ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D);
            }
        }

    }

    protected void onHitEntity(EntityRayTraceResult p_213868_1_) {
        super.onHitEntity(p_213868_1_);
        p_213868_1_.getEntity().hurt(DamageSource.thrown(this, this.getOwner()), 0.0F);
    }

    protected void onHit(RayTraceResult p_70227_1_) {
        super.onHit(p_70227_1_);
        if (!this.level.isClientSide) {
            ChickenEntity chickenentity = EntityType.CHICKEN.create(this.level);
            chickenentity.setAge(-24000);
            chickenentity.moveTo(this.getX(), this.getY(), this.getZ(), this.yRot, 0.0F);
            this.level.addFreshEntity(chickenentity);

            this.level.broadcastEntityEvent(this, (byte)3);
            this.remove();
        }

    }

    protected Item getDefaultItem() {
        return Registration.FragGranade.get();
    }
}

 

Registation.java

public class Registration {
    private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, DangerMod.MODID);
    private static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, DangerMod.MODID);

    public static void init() {
        ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

    public static final RegistryObject<Item> FragGranade = ITEMS.register("frag_granate", FragGrenade::new);

    public static final RegistryObject<EntityType<GranateEntity>>
            granateEntity = ENTITIES.register("granate_projectile",
            () -> EntityType.Builder.<GranateEntity>of(GranateEntity::new, EntityClassification.MISC)
                    .sized(0.25F, 0.25F)
                    .setShouldReceiveVelocityUpdates(false)
                    .build("granate_projectile"));
}

 

FragGrenade.java

public class FragGrenade extends Item {
    public FragGrenade() {
        super(new Properties().tab(ModSetup.ITEM_GROUP));
    }

    @Override
    public ActionResult<ItemStack> use(World world, PlayerEntity entity, Hand hand) {
        ItemStack itemstack = entity.getItemInHand(hand);
        world.playSound((PlayerEntity) null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));

        if (!world.isClientSide) {
            GranateEntity granateEntity = new GranateEntity(entity, world);
            granateEntity.setItem(itemstack);
            granateEntity.shootFromRotation(entity, entity.xRot, entity.yRot, 0.0F, 1F, 1F);
            world.addFreshEntity(granateEntity);
        }

          
        

         
    

 

Edited by idev
Link to post
Share on other sites

You need to override createSpawnPacket in your projectile entity and return NetworkHooks.getEntitySpawningPacket from it. Otherwise your entity will be present in game but won't render in the client, as you already experienced. You can find more useful infos here: https://github.com/TheGreyGhost/MinecraftByExample/tree/1-16-3-final/src/main/java/minecraftbyexample/mbe81_entity_projectile

Edited by Beethoven92

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to post
Share on other sites
Posted (edited)
10 minutes ago, Beethoven92 said:

You need to override createSpawnPacket in your projectile entity and return NetworkHooks.getEntitySpawningPacket from it. Otherwise your entity will be present in game but won't render in the client, as you already experienced. You can find more useful infos here: https://github.com/TheGreyGhost/MinecraftByExample/tree/1-16-3-final/src/main/java/minecraftbyexample/mbe81_entity_projectile

Thank you very much for the links, I may need them more than once. But, the problem is that I cannot override the method
createSpawnPacket

My editor shows an error: Method does not override method from its superclass

12.png

Edited by idev
Link to post
Share on other sites
1 minute ago, Beethoven92 said:

Where did you try to override that method? It is a method of the Entity class

public class GranateEntity extends ProjectileItemEntity {

    public GranateEntity(EntityType<GranateEntity> type, World world) {
        super(type, world);
    }

    public GranateEntity(LivingEntity entity, World world) {
        super(Registration.granateEntity.get(), entity, world);
    }

    public GranateEntity(double x, double y, double z, World world) {
        super(Registration.granateEntity.get(), x, y, z, world);
    }

    @Nonnull
    @Override
    public IPacket<?> createSpawnPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);
    }

    @Override
    public void tick() {
        super.tick();
    }

    @OnlyIn(Dist.CLIENT)
    public void handleEntityEvent(byte p_70103_1_) {
        if (p_70103_1_ == 3) {
            double d0 = 0.08D;

            for(int i = 0; i < 8; ++i) {
                this.level.addParticle(new ItemParticleData(ParticleTypes.ITEM, this.getItem()), this.getX(), this.getY(), this.getZ(), ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D);
            }
        }

    }

    protected void onHitEntity(EntityRayTraceResult p_213868_1_) {
        super.onHitEntity(p_213868_1_);
        p_213868_1_.getEntity().hurt(DamageSource.thrown(this, this.getOwner()), 0.0F);
    }

    protected void onHit(RayTraceResult p_70227_1_) {
        super.onHit(p_70227_1_);
        if (!this.level.isClientSide) {
            ChickenEntity chickenentity = EntityType.CHICKEN.create(this.level);
            chickenentity.setAge(-24000);
            chickenentity.moveTo(this.getX(), this.getY(), this.getZ(), this.yRot, 0.0F);
            this.level.addFreshEntity(chickenentity);

            this.level.broadcastEntityEvent(this, (byte)3);
            this.remove();
        }

    }

    protected Item getDefaultItem() {
        return Registration.FragGranade.get();
    }
}

 

Link to post
Share on other sites
3 minutes ago, Beethoven92 said:

Where did you try to override that method? It is a method of the Entity class

I duplicated GranateEntity above with the place where I entered createSpawnPacket, but got an error.

Link to post
Share on other sites
1 minute ago, Beethoven92 said:

Что значит вы продублировали GranateEntity? Пожалуйста, покажите свой код полностью ... возможно, ссылку на ваш репозиторий

There are a few things I tried to do for rendering. In the Networking and PacketSpawn class, but I'm not sure if this was needed at all. Took from an example


https://github.com/idev-hub/DangerMod

Link to post
Share on other sites

What do you currently need that PacketSpawn class for? Your entity currently doesn't render because you needed to override that createSpawnPacket method as shown above..it is very weird that it gives you an error on that..perhaps something wrong with your IDE?

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to post
Share on other sites
3 minutes ago, Beethoven92 said:

Для чего вам сейчас нужен этот класс PacketSpawn? Ваша сущность в настоящее время не отображается, потому что вам нужно переопределить этот метод createSpawnPacket, как показано выше ... очень странно, что он выдает вам ошибку в этом ... возможно, что-то не так с вашей IDE?

I don't even know, I thought it changed in version 16.5, so I went to the forum. The IDE can be said to be clean, like a clean installation of MC Forge, I even created an almost clean mod, removing all unnecessary, and I used PacketSpawn for tests

Link to post
Share on other sites

Oh, nice to know, my bad then! I am still using old mappings. Tip for the next time, whatever a method/field is called, you can use your IDE to see what methods or fields belongs to a certain class..in this case searching for a method with the same signature (return type and parameters) as the one you need and a name that seems to match what you want is a good starting point

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to post
Share on other sites
  • idev changed the title to [Solved] Rendering ProjectileItemEntity 1.16.5

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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 Privacy Policy.