Jump to content

[1.17.1] projectile erro


peanutexexe

Recommended Posts

error projectile shoot

code

Spoiler

Main


package net.peanutexe.PMW;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.*;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
import net.peanutexe.PMW.Entity.FMJ556En;
import net.peanutexe.PMW.registry.*;
import net.peanutexe.PMW.util.Gun556LeftClickPacket;
import net.peanutexe.PMW.util.LeftClickPacket;
import net.peanutexe.PMW.util.PacketHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.function.Supplier;
import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("pmw")
public class PMW
{
    // Directly reference a log4j LOGGER.
    public static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "pmw";

    public PMW() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);

        init();


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

    @Mod.EventBusSubscriber(modid = PMW.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public static class EventListener
    {
        @SubscribeEvent
        public static void emptyLeftClick(PlayerInteractEvent.LeftClickEmpty event)
        {
            PacketHandler.HANDLER.sendToServer(new LeftClickPacket());
        }
    }

    private void init() {
        BulletRegistry.init();
        GunRegistry.init();
        HealRegistry.init();
    }

    private void setup(final FMLCommonSetupEvent event) {
        // some preinit code
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
        PacketHandler.register();
    }

    /*public static final CreativeModeTab Heal_Tab = new CreativeModeTab("heal_tab") {
        @Override
        public ItemStack makeIcon() {
            return new ItemStack(HealRegistry.SALEWA.get());
        }
    };*/

    public static final CreativeModeTab Assault_Tab = new CreativeModeTab("assault_tab") {
        @Override
        public ItemStack makeIcon() {
            return new ItemStack(GunRegistry.HK416.get());
        }
    };

    /*public static final CreativeModeTab Carbine_Tab = new CreativeModeTab("carbine_tab") {
        @Override
        public ItemStack makeIcon() {
            return new ItemStack(GunRegistry.M4A1.get());
        }
    };*/

    public static final CreativeModeTab BulletGroup = new CreativeModeTab("bullet_tab") {
        @Override
        public ItemStack makeIcon() {
            return new ItemStack(BulletRegistry.FMJ556.get());
        }
    };

    private void enqueueIMC(final InterModEnqueueEvent event) {
        // some example code to dispatch IMC to another mod
        InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
    }

    private void ClientSetup(final FMLClientSetupEvent event) {

    }

    private void processIMC(final InterModProcessEvent event) {
        // some example code to receive and process InterModComms from other mods
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m->m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }
    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
        LOGGER.info("HELLO from server starting");
    }
}

BulletEntityRegistry


package net.peanutexe.PMW.registry;

import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fmllegacy.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.peanutexe.PMW.Entity.FMJ556En;
import net.peanutexe.PMW.PMW;


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

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

    public static final RegistryObject<EntityType<FMJ556En>> FMJ556Entity = ENTITIES.register("fmj556en", () -> EntityType.Builder.<FMJ556En>of(FMJ556En::new, MobCategory.MISC).sized(0.25f, 0.25f).clientTrackingRange(4).updateInterval(10).build(new ResourceLocation(PMW.MOD_ID, "fmj556en").toString()));
}

FMJ556En


package net.peanutexe.PMW.Entity;

import net.minecraft.network.protocol.Packet;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.fmllegacy.network.NetworkHooks;
import net.peanutexe.PMW.registry.BulletRegistry;
import net.peanutexe.PMW.registry.BulletEntityRegistry;

public class FMJ556En extends ThrowableItemProjectile {
    public static final EntityDataAccessor<ItemStack> FMJ556 = SynchedEntityData.defineId(FMJ556En.class, EntityDataSerializers.ITEM_STACK);
    public static final EntityDataAccessor<Byte> PIERCING_LEVEL = SynchedEntityData.defineId(FMJ556En.class, EntityDataSerializers.BYTE);

    public FMJ556En(EntityType<? extends ThrowableItemProjectile> p_37432_, Level world) {
        super(p_37432_, world);
    }

    public FMJ556En(LivingEntity entity, Level world) {
        super(BulletEntityRegistry.FMJ556Entity.get(), entity, world);
    }

    public FMJ556En(double x, double y, double z, Level world) {
        super(BulletEntityRegistry.FMJ556Entity.get(), x, y, z, world);
    }

    @Override
    protected Item getDefaultItem() {
        return BulletRegistry.BULLET_DEFAULT.get().asItem();
    }

    /*@Override
    protected void onImpact(RayTraceResult result) {

        if (result.getType() == RayTraceResult.Type.ENTITY) {
            Entity entity = ((EntityRayTraceResult) result).getEntity();
            int damage = 2;

            entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getEntity()), (float) damage);
        }
        if (!world.isRemote) {
            this.remove();
        }
    }*/

    public ItemStack getFMJ556() {
        return (ItemStack) this.entityData.get(FMJ556);
    }

    public double getSpeed() {
        return Math.sqrt(getDeltaMovement().x * getDeltaMovement().x + getDeltaMovement().y * getDeltaMovement().y + getDeltaMovement().z * getDeltaMovement().z);
    }
    public int getPiercingLevel() {
        return this.entityData.get(PIERCING_LEVEL);
    }

    @Override
    protected void onHit(HitResult p_37260_) {
        if (p_37260_.getType() == HitResult.Type.ENTITY) {
            Entity entity = ((EntityHitResult) p_37260_).getEntity();
            double damage = 1.5;
            entity.hurt(DamageSource.thrown(this, this.getOwner()), (float) damage);
        }
        if (!level.isClientSide) {
            this.remove(true);
        }
    }

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

HK416Fac


package net.peanutexe.PMW.Entity;

import net.minecraft.network.protocol.Packet;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.fmllegacy.network.NetworkHooks;
import net.peanutexe.PMW.registry.BulletRegistry;
import net.peanutexe.PMW.registry.BulletEntityRegistry;

public class FMJ556En extends ThrowableItemProjectile {
    public static final EntityDataAccessor<ItemStack> FMJ556 = SynchedEntityData.defineId(FMJ556En.class, EntityDataSerializers.ITEM_STACK);
    public static final EntityDataAccessor<Byte> PIERCING_LEVEL = SynchedEntityData.defineId(FMJ556En.class, EntityDataSerializers.BYTE);

    public FMJ556En(EntityType<? extends ThrowableItemProjectile> p_37432_, Level world) {
        super(p_37432_, world);
    }

    public FMJ556En(LivingEntity entity, Level world) {
        super(BulletEntityRegistry.FMJ556Entity.get(), entity, world);
    }

    public FMJ556En(double x, double y, double z, Level world) {
        super(BulletEntityRegistry.FMJ556Entity.get(), x, y, z, world);
    }

    @Override
    protected Item getDefaultItem() {
        return BulletRegistry.BULLET_DEFAULT.get().asItem();
    }

    /*@Override
    protected void onImpact(RayTraceResult result) {

        if (result.getType() == RayTraceResult.Type.ENTITY) {
            Entity entity = ((EntityRayTraceResult) result).getEntity();
            int damage = 2;

            entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getEntity()), (float) damage);
        }
        if (!world.isRemote) {
            this.remove();
        }
    }*/

    public ItemStack getFMJ556() {
        return (ItemStack) this.entityData.get(FMJ556);
    }

    public double getSpeed() {
        return Math.sqrt(getDeltaMovement().x * getDeltaMovement().x + getDeltaMovement().y * getDeltaMovement().y + getDeltaMovement().z * getDeltaMovement().z);
    }
    public int getPiercingLevel() {
        return this.entityData.get(PIERCING_LEVEL);
    }

    @Override
    protected void onHit(HitResult p_37260_) {
        if (p_37260_.getType() == HitResult.Type.ENTITY) {
            Entity entity = ((EntityHitResult) p_37260_).getEntity();
            double damage = 1.5;
            entity.hurt(DamageSource.thrown(this, this.getOwner()), (float) damage);
        }
        if (!level.isClientSide) {
            this.remove(true);
        }
    }

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

 

 

Link to comment
Share on other sites

error code

[11:46:17] [Server thread/FATAL]: Error executing task on Server
java.lang.NullPointerException: Registry Object not present: pmw:fmj556en
    at java.util.Objects.requireNonNull(Objects.java:334) ~[?:?]
    at net.minecraftforge.fmllegacy.RegistryObject.get(RegistryObject.java:120) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2372%2378!:?]
    at net.peanutexe.PMW.Entity.FMJ556En.<init>(FMJ556En.java:31) ~[%2377!:?]
    at net.peanutexe.PMW.Items.Gun.Assault.HK416Fac.use(HK416Fac.java:34) ~[%2377!:?]
    at net.minecraft.world.item.ItemStack.use(ItemStack.java:243) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.level.ServerPlayerGameMode.useItem(ServerPlayerGameMode.java:284) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.network.ServerGamePacketListenerImpl.handleUseItem(ServerGamePacketListenerImpl.java:995) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.network.protocol.game.ServerboundUseItemPacket.handle(ServerboundUseItemPacket.java:23) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.network.protocol.game.ServerboundUseItemPacket.handle(ServerboundUseItemPacket.java:7) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:21) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.TickTask.run(TickTask.java:17) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:139) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:22) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:775) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:162) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:112) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:758) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:752) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:100) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:737) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:687) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:258) ~[forge-1.17.1-37.0.8_mapped_official_1.17.1-recomp.jar%2373!:?]
    at java.lang.Thread.run(Thread.java:831) [?:?]

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.