Jump to content

[Solved] Projectile Entity is Invisible


CommandCore

Recommended Posts

My projectile is working completely as intended, but it's invisible for some reason. I think it has something to do with how I'm registering its renderer.

 

Here I'm using an item to spawn it, identical to how a dragon would shoot a fireball: 

 

 

Here's my Registry Object entry:

public static final RegistryObject<EntityType<HeartballEntity>> HEARTBALL_PROJECTILE = ENTITIES.register("heartball", () -> EntityType.Builder.<HeartballEntity>create(HeartballEntity::new, EntityClassification.MISC).size(0.25F, 0.25F).trackingRange(4).func_233608_b_(10).build("heartball"));

Here's the code in my main class that's handling the registry of the rendering:

private void doClientStuff(final FMLClientSetupEvent event)
    {
        registerEntityModels(event.getMinecraftSupplier());
    }

    private void registerEntityModels(Supplier<Minecraft> minecraft)
    {

        EntityRendererManager renderer = minecraft.get().getRenderManager();

        renderer.register(RegistryHandler.HEARTBALL_PROJECTILE.get(), new HeartballRenderer(renderer));

    }

(FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); is called in the constructor.)

 

HeartballEntity and HeartballRenderer are identical to DragonFireballEntity and DragonFireballRenderer for example purposes, with the exception of the texture in HeartballRenderer, which I have changed to a target texture of my own:

private static final ResourceLocation HEARTBALL_TEXTURE = new ResourceLocation(TwoDotXMod.MOD_ID + ":textures/entity/heartball.png");

 

I appreciate any help, let me know if more information is needed.

 

Cheers.

Edited by CommandCore
Link to comment
Share on other sites

  • 2 weeks later...
On 2/25/2021 at 11:57 PM, diesieben07 said:

Use RenderingRegistry.registerEntityRenderingHandler to register entity renderers.

I tried this with no luck:

RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.HEARTBALL_PROJECTILE.get(), HeartballRenderer::new);

 

Link to comment
Share on other sites

20 hours ago, diesieben07 said:

Show more of your code.

Sure:

 

HeartballRenderer.java

package com.agilapathy.twodotx.entities.heartball;

import com.agilapathy.twodotx.TwoDotXMod;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Matrix3f;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.registry.IRenderFactory;

import javax.annotation.Nullable;

@OnlyIn(Dist.CLIENT)
public class HeartballRenderer extends EntityRenderer<HeartballEntity> {


    private static final ResourceLocation HEARTBALL_TEXTURE = new ResourceLocation(TwoDotXMod.MOD_ID + ":textures/entity/heartball.png");
    private static final RenderType field_229044_e_ = RenderType.getEntityCutoutNoCull(HEARTBALL_TEXTURE);

    public HeartballRenderer(EntityRendererManager renderManagerIn) {
        super(renderManagerIn);
    }

    protected int getBlockLight(HeartballEntity entityIn, BlockPos partialTicks) {
        return 15;
    }

    public void render(HeartballEntity entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
        matrixStackIn.push();
        matrixStackIn.scale(2.0F, 2.0F, 2.0F);
        matrixStackIn.rotate(this.renderManager.getCameraOrientation());
        matrixStackIn.rotate(Vector3f.YP.rotationDegrees(180.0F));
        MatrixStack.Entry matrixstack$entry = matrixStackIn.getLast();
        Matrix4f matrix4f = matrixstack$entry.getMatrix();
        Matrix3f matrix3f = matrixstack$entry.getNormal();
        IVertexBuilder ivertexbuilder = bufferIn.getBuffer(field_229044_e_);
        func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 0.0F, 0, 0, 1);
        func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 1.0F, 0, 1, 1);
        func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 1.0F, 1, 1, 0);
        func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 0.0F, 1, 0, 0);
        matrixStackIn.pop();
        super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
    }

    private static void func_229045_a_(IVertexBuilder p_229045_0_, Matrix4f p_229045_1_, Matrix3f p_229045_2_, int p_229045_3_, float p_229045_4_, int p_229045_5_, int p_229045_6_, int p_229045_7_) {
        p_229045_0_.pos(p_229045_1_, p_229045_4_ - 0.5F, (float)p_229045_5_ - 0.25F, 0.0F).color(255, 255, 255, 255).tex((float)p_229045_6_, (float)p_229045_7_).overlay(OverlayTexture.NO_OVERLAY).lightmap(p_229045_3_).normal(p_229045_2_, 0.0F, 1.0F, 0.0F).endVertex();
    }

    /**
     * Returns the location of an entity's texture.
     */
    @Override
    public ResourceLocation getEntityTexture(HeartballEntity entity) {
        return HEARTBALL_TEXTURE;
    }
}

 

HeartballEntity.java

package com.agilapathy.twodotx.entities.heartball;

import java.util.List;

import com.agilapathy.twodotx.util.RegistryHandler;
import net.minecraft.entity.*;
import net.minecraft.entity.projectile.DamagingProjectileEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class HeartballEntity extends DamagingProjectileEntity{
    public HeartballEntity(EntityType<? extends HeartballEntity> p_i50171_1_, World p_i50171_2_) {
        super(p_i50171_1_, p_i50171_2_);
    }

    @OnlyIn(Dist.CLIENT)
    public HeartballEntity(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ) {
        super(RegistryHandler.HEARTBALL_PROJECTILE.get(), x, y, z, accelX, accelY, accelZ, worldIn);
    }

    public HeartballEntity(World worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ) {
        super(RegistryHandler.HEARTBALL_PROJECTILE.get(), shooter, accelX, accelY, accelZ, worldIn);
    }

    /**
     * Called when this EntityFireball hits a block or entity.
     */
    protected void onImpact(RayTraceResult result) {
        super.onImpact(result);
        Entity entity = this.func_234616_v_();
        if (result.getType() != RayTraceResult.Type.ENTITY || !((EntityRayTraceResult)result).getEntity().isEntityEqual(entity)) {
            if (!this.world.isRemote) {
                List<LivingEntity> list = this.world.getEntitiesWithinAABB(LivingEntity.class, this.getBoundingBox().grow(4.0D, 2.0D, 4.0D));
                AreaEffectCloudEntity areaeffectcloudentity = new AreaEffectCloudEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ());
                if (entity instanceof LivingEntity) {
                    areaeffectcloudentity.setOwner((LivingEntity)entity);
                }

                areaeffectcloudentity.setParticleData(ParticleTypes.DRAGON_BREATH);
                areaeffectcloudentity.setRadius(3.0F);
                areaeffectcloudentity.setDuration(600);
                areaeffectcloudentity.setRadiusPerTick((7.0F - areaeffectcloudentity.getRadius()) / (float)areaeffectcloudentity.getDuration());
                areaeffectcloudentity.addEffect(new EffectInstance(Effects.INSTANT_DAMAGE, 1, 1));
                if (!list.isEmpty()) {
                    for(LivingEntity livingentity : list) {
                        double d0 = this.getDistanceSq(livingentity);
                        if (d0 < 16.0D) {
                            areaeffectcloudentity.setPosition(livingentity.getPosX(), livingentity.getPosY(), livingentity.getPosZ());
                            break;
                        }
                    }
                }

                this.world.playEvent(2006, this.getPosition(), this.isSilent() ? -1 : 1);
                this.world.addEntity(areaeffectcloudentity);
                this.remove();
            }

        }
    }

    /**
     * Returns true if other Entities should be prevented from moving through this Entity.
     */
    public boolean canBeCollidedWith() {
        return false;
    }

    /**
     * Called when the entity is attacked.
     */
    public boolean attackEntityFrom(DamageSource source, float amount) {
        return false;
    }

    protected IParticleData getParticle() {
        return ParticleTypes.DRAGON_BREATH;
    }

    protected boolean isFireballFiery() {
        return false;
    }
}

 

TwoDotXMod.java (Main class)

package com.agilapathy.twodotx;

import com.agilapathy.twodotx.capabilities.*;
import com.agilapathy.twodotx.entities.heartball.HeartballEntity;
import com.agilapathy.twodotx.entities.heartball.HeartballRenderer;
import com.agilapathy.twodotx.gen.GenerationEvents;
import com.agilapathy.twodotx.util.ClientEvents;
import com.agilapathy.twodotx.util.RegistryHandler;
import com.agilapathy.twodotx.util.functions.*;
import net.minecraft.block.DispenserBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.SpriteRenderer;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.function.Supplier;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("twodotx")
public class TwoDotXMod
{
    private static final String PROTOCOL_VERSION = "1";
    public static final SimpleChannel PACKET_HANDLER = NetworkRegistry.newSimpleChannel(new ResourceLocation("twodotx", "twodotx"),
            () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals);

    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "twodotx";

    public TwoDotXMod() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        //FMLJavaModLoadingContext.get().getModEventBus().addListener(GenerationMain::generate);

        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        //Register Other Stuff

        RegistryHandler.init();

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
    }

    private void doClientStuff(final FMLClientSetupEvent event)
    {
        RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.HEARTBALL_PROJECTILE.get(), HeartballRenderer::new);
    }

}

 

RegistryHandler.java

package com.agilapathy.twodotx.util;

import com.agilapathy.twodotx.TwoDotXMod;
import com.agilapathy.twodotx.blocks.*;
import com.agilapathy.twodotx.entities.heartball.HeartballEntity;
import com.agilapathy.twodotx.items.*;
import com.agilapathy.twodotx.util.enums.CustomArmorMaterial;
import com.agilapathy.twodotx.util.enums.CustomItemTier;
import net.minecraft.block.*;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentType;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.*;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

import static net.minecraftforge.registries.DeferredRegister.create;

public class RegistryHandler
{
    public static final DeferredRegister<EntityType<?>> ENTITIES = create(ForgeRegistries.ENTITIES, TwoDotXMod.MOD_ID);

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

    //Entities
    public static final RegistryObject<EntityType<HeartballEntity>> HEARTBALL_PROJECTILE = ENTITIES.register("heartball", () -> EntityType.Builder.<HeartballEntity>create(HeartballEntity::new, EntityClassification.MISC).size(0.25F, 0.25F).trackingRange(4).func_233608_b_(10).build("heartball"));
}

 

Link to comment
Share on other sites

13 minutes ago, diesieben07 said:
  • Do not use @OnlyIn.
  • Custom entities must override Entity#createSpawnPacket and call NetworkHooks.getEntitySpawningPacket.
  • Use @Override when overriding methods.

Solved. Removed @OnlyIn from HeartballEntity and added this to the end of my Entity class:

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

Thanks for the help,

 

Cheers.

Link to comment
Share on other sites

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.