Jump to content

[1.16.1] Custom Projectile not working (creating an EntityType)


majesity
 Share

Recommended Posts

Hi all, for my mod I am making a spider that shoots poisonous projectiles at the player (called a crawler) and I want to make a custom projectile for this. I have made the projectile entity class and I know that I need to make the rendering class, but before I do that I need to make a custom EntityType in order to even create the projectile entity in the world. Here is my projectile class:

public class CrawlerVenomEntity extends AbstractCrawlerVenomEntity {
    public int explosionPower = 0;
    public double explosionRadius = 2.0;

    public CrawlerVenomEntity(EntityType<CrawlerVenomEntity> type, World worldIn) {
        super(type, worldIn);
    }

    @OnlyIn(Dist.CLIENT)
    public CrawlerVenomEntity(EntityType<? extends CrawlerVenomEntity> type, World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ) {
        super(type, x, y, z, accelX, accelY, accelZ, worldIn);
        this.setVelocity(accelX, accelY, accelZ);
    }

    /**
     * Called when this EntityFireball hits a block or entity.
     */
    protected void onImpact(RayTraceResult result) {
        super.onImpact(result);
        if (!this.world.isRemote) {
            boolean flag = net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.func_234616_v_());
            this.world.playSound(this.getPosX(),this.getPosY(),this.getPosZ(), SoundEvents.ENTITY_SPIDER_AMBIENT, SoundCategory.HOSTILE,1.0F,1.0F,true);
            World world = this.getEntityWorld();
            world.addParticle(ParticleTypes.ITEM_SLIME,this.getPosX(),this.getPosY()+0.5,this.getPosZ(),0,1,0);
            world.addParticle(ParticleTypes.ITEM_SLIME,this.getPosX(),this.getPosY()+1.5,this.getPosZ(),0,1,0);
            world.addParticle(ParticleTypes.ITEM_SLIME,this.getPosX(),this.getPosY()+1.0,this.getPosZ(),0,1,0);

            // this.world.createExplosion((Entity)null, this.getPosX(), this.getPosY(), this.getPosZ(), (float)this.explosionPower, flag, flag ? Explosion.Mode.DESTROY : Explosion.Mode.NONE);
            Vector3d victor = result.getHitVec();
            AxisAlignedBB aabb = new AxisAlignedBB(this.getPosX()-explosionRadius,this.getPosY()-explosionRadius,this.getPosZ()-explosionRadius,
                    this.getPosX()+explosionRadius,this.getPosY()+explosionRadius,this.getPosZ()+explosionRadius);
            for(LivingEntity e:this.world.getEntitiesWithinAABB(LivingEntity.class,aabb)) {
                e.attackEntityFrom(DamageSource.MAGIC,5);
                e.addPotionEffect(new EffectInstance(Effects.POISON,80,1));
            }
            this.remove();
        }

    }

    /**
     * Called when the arrow hits an entity
     */
    protected void onEntityHit(EntityRayTraceResult p_213868_1_) {
        super.onEntityHit(p_213868_1_);
        if (!this.world.isRemote) {
            Entity entity = p_213868_1_.getEntity();
            Entity entity1 = this.func_234616_v_();
            entity.attackEntityFrom(DamageSource.MAGIC, 6.0F);
            if (entity1 instanceof LivingEntity) {
                this.applyEnchantments((LivingEntity)entity1, entity);
            }

        }
    }

    public void writeAdditional(CompoundNBT compound) {
        super.writeAdditional(compound);
        compound.putInt("ExplosionPower", this.explosionPower);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readAdditional(CompoundNBT compound) {
        super.readAdditional(compound);
        if (compound.contains("ExplosionPower", 99)) {
            this.explosionPower = compound.getInt("ExplosionPower");
        }

    }

    protected ItemStack getStack() {
        return new ItemStack(Items.SLIME_BALL);
    }

    @OnlyIn(Dist.CLIENT)
    public ItemStack getItem() {
        ItemStack itemstack = this.getStack();
        return itemstack.isEmpty() ? new ItemStack(Items.SLIME_BALL) : itemstack;
    }

}

Here is the AbstractCrawlerVenomEntity class:

@OnlyIn(
        value = Dist.CLIENT,
        _interface = IRendersAsItem.class
)
public abstract class AbstractCrawlerVenomEntity extends DamagingProjectileEntity implements IRendersAsItem {
    private static final DataParameter<ItemStack> STACK = EntityDataManager.createKey(net.minecraft.entity.projectile.AbstractFireballEntity.class, DataSerializers.ITEMSTACK);

    public AbstractCrawlerVenomEntity(EntityType<? extends AbstractCrawlerVenomEntity> p_i50166_1_, World p_i50166_2_) {
        super(p_i50166_1_, p_i50166_2_);
    }

    public AbstractCrawlerVenomEntity(EntityType<? extends AbstractCrawlerVenomEntity> p_i50167_1_, double p_i50167_2_, double p_i50167_4_, double p_i50167_6_, double p_i50167_8_, double p_i50167_10_, double p_i50167_12_, World p_i50167_14_) {
        super(p_i50167_1_, p_i50167_2_, p_i50167_4_, p_i50167_6_, p_i50167_8_, p_i50167_10_, p_i50167_12_, p_i50167_14_);
    }

    public void setStack(ItemStack p_213898_1_) {
        if (p_213898_1_.getItem() != Items.FIRE_CHARGE || p_213898_1_.hasTag()) {
            this.getDataManager().set(STACK, Util.make(p_213898_1_.copy(), (p_213897_0_) -> {
                p_213897_0_.setCount(1);
            }));
        }

    }

    protected ItemStack getStack() {
        return this.getDataManager().get(STACK);
    }

    @OnlyIn(Dist.CLIENT)
    public ItemStack getItem() {
        ItemStack itemstack = this.getStack();
        return itemstack.isEmpty() ? new ItemStack(Items.FIRE_CHARGE) : itemstack;
    }

    protected void registerData() {
        this.getDataManager().register(STACK, ItemStack.EMPTY);
    }

    public void writeAdditional(CompoundNBT compound) {
        super.writeAdditional(compound);
        ItemStack itemstack = this.getStack();
        if (!itemstack.isEmpty()) {
            compound.put("Item", itemstack.write(new CompoundNBT()));
        }

    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readAdditional(CompoundNBT compound) {
        super.readAdditional(compound);
        ItemStack itemstack = ItemStack.read(compound.getCompound("Item"));
        this.setStack(itemstack);
    }
}

And I am trying to create an EntityType for this class so I can spawn it in by doing the following in my EntityTypesInit:

public class ModEntityTypes {

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

    // All my other Entity Types here

    // Projectile Entity Types
      public static final RegistryObject<EntityType<CrawlerVenomEntity>> CRAWLER_VENOM = ENTITY_TYPES.register("crawler_venom",
            () -> EntityType.Builder.create(CrawlerVenomEntity::new, EntityClassification.MISC)
                    .size(1.0f,0.5f)
                    .build(new ResourceLocation(MajCraft.MOD_ID, "crawler_venom").toString())
    );

}

But for some reason it does not like the CrawlerVenomEntity::new and I do not know why... I've played around with changing the data types of the parameters.

To spawn in the entity I want to do something like this: 

CrawlerVenomEntity test = new CrawlerVenomEntity(ModEntityTypes.CRAWLER_VENOM,worldIn,playerIn.getPosX()+playerIn.getForward().getX(),playerIn.getPosY()+1.25,playerIn.getPosZ()+playerIn.getForward().getZ(),playerIn.getForward().getX(),playerIn.getForward().getY(),playerIn.getForward().getZ())

 

Why isn't this working? Thank you for your time!

Link to comment
Share on other sites

      public static final RegistryObject<EntityType<CrawlerVenomEntity>> CRAWLER_VENOM = ENTITY_TYPES.register("crawler_venom",
            () -> EntityType.Builder.<CrawlerVenomEntity> <----- create(CrawlerVenomEntity::new, EntityClassification.MISC)
                    .size(1.0f,0.5f)
                    .build(new ResourceLocation(MajCraft.MOD_ID, "crawler_venom").toString())
    );

https://www.tutorialspoint.com/java/java_generics.htm

Edited by poopoodice
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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! I downloaded the MrCrayfishs Furniture mod for 1.19.3. I also have 1.19.3 for forge and optifine. It's the only mod in my mods folder. It would be nice if anyone could help me. xx This is the crash report: ---- Minecraft Crash Report ---- // My bad. Time: 2023-01-30 13:17:38 Description: Mod loading error has occurred java.lang.Exception: Mod Loading has failed     at net.minecraftforge.logging.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:55) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.completeModLoading(ClientModLoader.java:167) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:588) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.Util.m_137521_(Util.java:432) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$3(Minecraft.java:582) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.gui.screens.LoadingOverlay.m_86412_(LoadingOverlay.java:137) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:920) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1135) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:713) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:212) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.0.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {} -- MOD cfm -- Details:     Caused by 0: java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider         at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}         at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}         at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}         at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}         at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}         at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}         at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}         at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}         at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}     Mod File: /C:/Users/User/AppData/Roaming/.minecraft/mods/MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar     Failure message: MrCrayfish's Furniture Mod (cfm) has failed to load correctly         java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider     Mod Version: 7.0.0-pre34     Mod Issue URL: https://github.com/MrCrayfish/MrCrayfishFurnitureMod/issues     Exception message: java.lang.ClassNotFoundException: net.minecraft.data.tags.BlockTagsProvider Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}     at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}     at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}     at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}     at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}     at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} -- System Details -- Details:     Minecraft Version: 1.19.3     Minecraft Version ID: 1.19.3     Operating System: Windows 10 (amd64) version 10.0     Java Version: 17.0.3, Microsoft     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft     Memory: 241410776 bytes (230 MiB) / 503316480 bytes (480 MiB) up to 2147483648 bytes (2048 MiB)     CPUs: 4     Processor Vendor: AuthenticAMD     Processor Name: AMD FX-8800P Radeon R7, 12 Compute Cores 4C+8G      Identifier: AuthenticAMD Family 21 Model 96 Stepping 1     Microarchitecture: unknown     Frequency (GHz): 2.10     Number of physical packages: 1     Number of physical CPUs: 4     Number of logical CPUs: 4     Graphics card #0 name: AMD Radeon R7 Graphics     Graphics card #0 vendor: Advanced Micro Devices, Inc. (0x1002)     Graphics card #0 VRAM (MB): 256.00     Graphics card #0 deviceId: 0x9874     Graphics card #0 versionInfo: DriverVersion=27.20.1034.6     Memory slot #0 capacity (MB): 8192.00     Memory slot #0 clockSpeed (GHz): 2.13     Memory slot #0 type: DDR4     Memory slot #1 capacity (MB): 8192.00     Memory slot #1 clockSpeed (GHz): 2.13     Memory slot #1 type: DDR4     Virtual memory max (MB): 18519.90     Virtual memory used (MB): 7647.12     Swap memory total (MB): 2432.00     Swap memory used (MB): 35.46     JVM Flags: 9 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     ModLauncher: 10.0.8+10.0.8+main.0ef7e830     ModLauncher launch target: forgeclient     ModLauncher naming: srg     ModLauncher services:          mixin-0.8.5.jar mixin PLUGINSERVICE          eventbus-6.0.3.jar eventbus PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar slf4jfixer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar object_holder_definalize PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtime_enum_extender PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar capability_token_subclass PLUGINSERVICE          accesstransformers-8.0.4.jar accesstransformer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtimedistcleaner PLUGINSERVICE          modlauncher-10.0.8.jar mixin TRANSFORMATIONSERVICE          modlauncher-10.0.8.jar fml TRANSFORMATIONSERVICE      FML Language Providers:          minecraft@1.0         lowcodefml@null         javafml@null     Mod List:          client-1.19.3-20221207.122022-srg.jar             |Minecraft                     |minecraft                     |1.19.3              |COMMON_SET|Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f         forge-1.19.3-44.1.0-universal.jar                 |Forge                         |forge                         |44.1.0              |COMMON_SET|Manifest: 84:ce:76:e8:45:35:e4:0e:63:86:df:47:59:80:0f:67:6c:c1:5f:6e:5f:4d:b3:54:47:1a:9f:7f:ed:5e:f2:90         MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar        |MrCrayfish's Furniture Mod    |cfm                           |7.0.0-pre34         |ERROR     |Manifest: NOSIGNATURE     Crash Report UUID: d668c79d-366a-4acb-9754-f4cd52ab88cb     FML: 44.1     Forge: net.minecraftforge:44.1.0
    • thanks for your help. I found that issue: https://github.com/MinecraftForge/MinecraftForge/issues/8498
    • i'm trying to have my friend join my modded server. I gave them all the mods i have installed and the 'mixmatched mod list' keeps poping up.
  • Topics

×
×
  • Create New...

Important Information

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