Jump to content

Recommended Posts

Posted (edited)

Like a snowball

 

but, it has no throwing animation

 

my entity

public class FirecrackerEntity extends ProjectileItemEntity {

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

    public FirecrackerEntity(World world, LivingEntity livingEntity) {
        super(ModEntityTypes.FIRE_CRACKER.get(), livingEntity, world);
    }

    @Override
    protected Item getDefaultItem() {
        return ModItems.FIRE_CRACKER.get();
    }

    @OnlyIn(Dist.CLIENT)
    private IParticleData getParticle() {
        ItemStack itemstack = this.getItemRaw();
        return itemstack.isEmpty() ? ParticleTypes.ITEM_SNOWBALL : new ItemParticleData(ParticleTypes.ITEM, itemstack);
    }

    @OnlyIn(Dist.CLIENT)
    @Override
    public void handleEntityEvent(byte height) {
        if (height == 3) {
            IParticleData iparticledata = this.getParticle();
            for (int i = 0; i < 8; ++i) {
                this.level.addParticle(iparticledata, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D);
            }
        }

    }
}

 

my item:

public class Firecracker extends Item {
    public Firecracker() {
        super(new Properties().tab(GroupDefine.MISC).stacksTo(16));
    }

    @Override
    public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
        ItemStack itemstack = player.getItemInHand(hand);
        world.playSound(null, player.getX(), player.getY(), player.getZ(), ModSounds.FIRE_CRACKER.get(),
                SoundCategory.VOICE, 1F, 1F);
        if (!world.isClientSide) {
            FirecrackerEntity firecracker = new FirecrackerEntity(world, player);
            firecracker.setItem(itemstack);
            firecracker.shootFromRotation(player, player.xRot, player.yRot, 0.0F, 1.5F, 1.0F);
            world.addFreshEntity(firecracker);
        }
        if (!player.abilities.instabuild) {
            itemstack.shrink(1);
        }
        return ActionResult.sidedSuccess(itemstack, world.isClientSide());
    }
}

 

entity register


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

    public static final RegistryObject<EntityType<FirecrackerEntity>> FIRE_CRACKER = ENTITY_TYPE.register(
            "fire_cracker",
            () -> EntityType.Builder.<FirecrackerEntity>of(FirecrackerEntity::new,
                            EntityClassification.MISC).sized(0.5f, 0.5f)
                    .build(new ResourceLocation(ApplicationConstants.MOD_ID, "fire_cracker").toString()));

    public static void register(IEventBus bus) {
        ENTITY_TYPE.register(bus);
    }

my entity class . It doesn't seem to be working, how can I make it run?

 

look: https://error-1254387167.cos.ap-chengdu.myqcloud.com/20211225/2021-12-25-18-24-35.avi

Edited by Spring
Posted (edited)
  On 12/25/2021 at 10:18 AM, Spring said:
ENTITY_TYPE.register(bus);
Expand  

Then test if this line is being executed (print something in console etc.)

Edit:

Also: does the Entity have a model? Try throwing it with Bounding boxes (F3 + B) enabled

Edited by OutCraft

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted

First:

Can you see a white cube when Bounding boxes (F3 + B) are enabled and you throw it?

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted (edited)

Also not when you summon it?

Edited by OutCraft

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted

...

Try changing the extending class from FirecrackerEntity to just Entity

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted (edited)

I copied your code and tried it, but for me it crashes:

"java.lang.NullPointerException: Cannot invoke "net.minecraft.client.renderer.entity.EntityRenderer.shouldRender(net.minecraft.world.entity.Entity, net.minecraft.client.renderer.culling.Frustum, double, double, double)" because "entityrenderer" is null"

This means that the Entity doesn't have a renderer or model.

Does it crash also for you?

Edited by OutCraft
Spelling

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
  On 12/25/2021 at 11:12 AM, OutCraft said:

I copied your code and tried it, but for me it crashes:

"java.lang.NullPointerException: Cannot invoke "net.minecraft.client.renderer.entity.EntityRenderer.shouldRender(net.minecraft.world.entity.Entity, net.minecraft.client.renderer.culling.Frustum, double, double, double)" because "entityrenderer" is null"

This means that the Entity doesn't have a model.

Does it crash also for you?

Expand  

 

add this:

MinecraftForge.EVENT_BUS.register(this);

ModEntityTypes.register(modEventBus);

try again?

Posted
  On 12/25/2021 at 11:15 AM, Spring said:

 

add this:

MinecraftForge.EVENT_BUS.register(this);

ModEntityTypes.register(modEventBus);

try again?

Expand  

Because I have no problem here, but it does not have a model, how can I add a model?

Posted
  On 12/25/2021 at 11:15 AM, Spring said:
MinecraftForge.EVENT_BUS.register(this);

ModEntityTypes.register(modEventBus);
Expand  

I added this, but it crashes because it doesn't have a renderer. Does your Entity have a renderer?

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
  On 12/25/2021 at 11:24 AM, OutCraft said:

I added this, but it crashes because it doesn't have a renderer. Does your Entity have a renderer?

Expand  

No, my code is from SnowballEntity class, I didn't see vanilla try this.. So, what should I do.

Posted (edited)

Vanilla does this in the Client renderer registry:

	@SubscribeEvent
	public static void registerEntityRenders(EntityRenderersEvent.RegisterRenderers event) {
		event.registerEntityRenderer(EntityList.FIRE_CRACKER.get(), ThrownItemRenderer::new);
	}

I did the same and now it works!

Edited by OutCraft

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted

But you need a texture for the Item, otherwise it's just black-pink

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted (edited)
  On 12/25/2021 at 11:33 AM, OutCraft said:

Vanilla does this in the Client renderer registry:

	@SubscribeEvent
	public static void registerEntityRenders(EntityRenderersEvent.RegisterRenderers event) {
		event.registerEntityRenderer(EntityList.FIRE_CRACKER.get(), ThrownItemRenderer::new);
	}

I did the same and now it works!

Expand  

you version ?I can't use this code

Edited by Spring
Posted (edited)
  On 12/25/2021 at 11:38 AM, Spring said:

you version ? 

Expand  

1.16.5, but you need to change 

  On 12/25/2021 at 11:38 AM, Spring said:
EntityList.FIRE_CRACKER.get()
Expand  

to

ModEntityTypes.FIRE_CRACKER.get()

because your EntityTypes class is named "ModEntityTypes"

Edited by OutCraft

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted (edited)
  On 12/25/2021 at 11:43 AM, OutCraft said:

1.16.5, but you need to change 

 

to

ModEntityTypes.FIRE_CRACKER.get()

because your EntityTypes class is named "ModEntityTypes"

Expand  

yes,i know,but i no class: EntityRenderersEvent、ThrownItemRenderer

 

my forge: 1.16.5-36.2.2

Edited by Spring
Posted

Do you use the Mojang or MCP mappings?

Also you can just search in your IDE for something like RenderEvent and it should show up

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You will find the crash-report or log in your minecraft directory (crash-report or logs folder)
    • Use a modpack which is using these 2 mods as working base:   https://www.curseforge.com/minecraft/modpacks/life-in-the-village-3
    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
  • Topics

×
×
  • Create New...

Important Information

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