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

[1.17.1] projectile erro


 Share

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.

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

    • This usually happens because of a bad manifest (mods.toml). Can you show us what's in your src folder?
    • Don't change it, the launcher comes with it configured properly.
    • Hello all. I am trying to implement oil into my mod (I know I know, unoriginal). But I just can't seem to get it to work. (System/Minecraft information: Java 17, forge: 1.17.1-37.0.95, mappings: official) I am using DeferredRegisters. In the current configuration, the bucket doesn't do anything most of the time, the block doesn't appear and doesn't flow. I am extending "ForgeFlowingFluid". It seems in LiquidBlock there are two constructors, one deprecated taking in a Fluid, the other takes in a supplier/RegistryObject<Fluid>. Because I am using DeferredRegisters, I have to use the second one, because blocks are registered before fluids. But it seems that in the code, most of it relies on the LiquidBlock.fluid field, which never gets set in the second constructor. I tried hacking in a solution with a "Fixed" version of LiquidBlock: public class FixedLiquidBlock extends LiquidBlock { private static final List<FixedLiquidBlock> liquidBlocksNeedingFixing = new ArrayList<>(); // Check if the supplier is a registry object. If it is, and the value is not null, set the value of the fluid field, else mark it so that it gets set later. public FixedLiquidBlock(Supplier<? extends FlowingFluid> supplier, Properties properties) { super(supplier, properties); try { if (supplier instanceof RegistryObject registryObject && registryObject.get() != null) { try { Class<?> class_ = LiquidBlock.class; Field fluidField = ObfuscationReflectionHelper.findField(class_, "fluid"); fluidField.setAccessible(true); fluidField.set(this, supplier.get()); } catch (Exception e) { throw new RuntimeException(e); } } } catch (NullPointerException ignored) {} liquidBlocksNeedingFixing.add(this); } @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) private static class FixedLiquidBlockEvents { @SubscribeEvent(priority = EventPriority.LOWEST) // Force the event to be called last // After registration of fluids is finished, set the fluids field. public static void onFluidsRegister(RegistryEvent<Fluid> fluidRegistryEvent) { for (FixedLiquidBlock fixedLiquidBlock : liquidBlocksNeedingFixing) { try { Class<?> class_ = LiquidBlock.class; Field fluidField = ObfuscationReflectionHelper.findField(class_, "fluid"); fluidField.setAccessible(true); fluidField.set(fixedLiquidBlock, fixedLiquidBlock.getFluid()); } catch (Exception e) { throw new RuntimeException(e); } } } } } But clearly what I'm doing is stupid because it still doesn't work. I even tried without my hacky solution, and it still didn't work! Am I doing something wrong? Should I be extending something else? What else should I do?   Code for fluid, OilFluid.java:   public abstract class OilFluid extends ForgeFlowingFluid { protected OilFluid() { super(new ForgeFlowingFluid.Properties( Source::new, Flowing::new, FluidAttributes.builder( new ResourceLocation(MiniTech.MODID, "block/oil_still"), new ResourceLocation(MiniTech.MODID, "block/oil_flow") ).overlay(new ResourceLocation(MiniTech.MODID, "block/oil_overlay")) .translationKey("block." + MiniTech.MODID + ".oil") .color(0xffffff))); } public static class Flowing extends OilFluid { public Flowing() { registerDefaultState(getStateDefinition().any().setValue(LEVEL, 7)); } @Override protected void createFluidStateDefinition(StateDefinition.Builder<Fluid, FluidState> p_76476_) { super.createFluidStateDefinition(p_76476_); p_76476_.add(LEVEL); } @Override public int getAmount(FluidState p_76480_) { return p_76480_.getValue(LEVEL); } @Override public boolean isSource(FluidState p_76478_) { return false; } } public static class Source extends OilFluid { @Override public int getAmount(FluidState p_76485_) { return 8; } @Override public boolean isSource(FluidState p_76483_) { return true; } } } Code for ModBlocks.java:   public class ModBlocks { private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MiniTech.MODID); public static final RegistryObject<RefineryFurnaceBlock> REFINERY_FURNACE = BLOCKS.register("refinery_furnace", () -> new RefineryFurnaceBlock(BlockBehaviour.Properties.of(Material.STONE).requiresCorrectToolForDrops().strength(3.5F).lightLevel(litBlockEmission(13)))); // Fluids public static final RegistryObject<LiquidBlock> OIL = BLOCKS.register("oil", () -> new FixedLiquidBlock(ModFluids.OIL, BlockBehaviour.Properties.of(Material.WATER).noCollission().strength(100.0F).noDrops())); public static void register(IEventBus eventBus) { BLOCKS.register(eventBus); } private static ToIntFunction<BlockState> litBlockEmission(int lightLevel) { return (blockState) -> { return blockState.getValue(BlockStateProperties.LIT) ? lightLevel : 0; }; } }  
    • No, no and no. The server knows the sending player, so the UUID is unnecessary. If you really needed to send a player (or any entity) across, you'd send the entity ID, not the UUID. The button name is irrelevant, if anything you'd send an Enum that specifies the button (if multiple buttons needs to be sent). The block position is also known on the server, sending it again only allows for cheats (if you don't validate it on the server, at which point you might as well just not send it at all).
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.