Jump to content

Recommended Posts

Posted (edited)

I don't Think in event.enqueueWork()

 

this is my Main

package net.peanutexe.PMW;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
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.fmlclient.registry.RenderingRegistry;
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
import net.peanutexe.PMW.Items.Entity.FMJ556En;
import net.peanutexe.PMW.registry.BulletRegistry;
import net.peanutexe.PMW.registry.EntityList;
import net.peanutexe.PMW.registry.GunRegistry;
import net.peanutexe.PMW.registry.HealRegistry;
import net.peanutexe.PMW.util.Gun556LeftClickPacket;
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);

        //FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);

        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 Gun556LeftClickPacket());
        }
    }

    private void init() {
        BulletRegistry.init();
        GunRegistry.init();
        EntityList.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 clientSetup(final FMLClientSetupEvent event) {
        registerEntityModels(event.enqueueWork());
    }

    private void registerEntityModels(Supplier<Minecraft> minecraft) {
        ItemRenderer renderer = minecraft.get().getItemRenderer();

        RenderingRegistry.registerEntityRenderingHandler(EntityList.FMJ556Entity.get(), (renderManager) -> new Sprite(renderManager, renderer));
    }

    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 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");
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here
            LOGGER.info("HELLO from Register Block");
        }
    }
}

EntityList.java

package net.peanutexe.PMW.registry;

import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
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.Items.Entity.FMJ556En;
import net.peanutexe.PMW.PMW;

public class EntityList {

    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(
            "fmj556_en",
            () -> EntityType.Builder
                    .<FMJ556En>of(FMJ556En::new, MobCategory.MISC)
                    .sized(0.25f, 0.25f)
                    .build("fmj556_en"));
}

FMJ556En.java

package net.peanutexe.PMW.Items.Entity;

import net.minecraft.network.protocol.Packet;
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.item.Item;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
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.EntityList;

public class FMJ556En extends ThrowableItemProjectile {
    public static final float BASE_SPEED = 20F;
    public static final int TICKS = 1;

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

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

    public FMJ556En(double x, double y, double z, Level world) {
        super(EntityList.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();
        }
    }*/

    @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);
    }
}

now I don't doing Runs

Edited by peanutexexe
  • peanutexexe changed the title to [solved][1.17.1] how to make Entity Models Register?

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

    • I myself am quite new to the modding scene, I started modding in February but have been in development hell a lot and have struggled to focus on one mod though I have been developing the current mod I've been working on since September and have made a lot of progress; during this time I have found a lot of helpful resources and have learnt a lot of things.    1. You can, I have had no Java experience previously and since modding have managed to be quite knowledgeable in Java.   2. Modding does not require massive teams, I and many others work alone, though having a team is certainly helpful in the modding process to get things done in a quicker and more organised way.   3. I absolutely have to recommend ModdingByKaupenjoe, he makes loads of tutorials for Minecraft from 1.16.5 and above with support for Forge, Fabric, and as of his 1.21 tutorials, Neoforge. These tutorials are really well made, covering almost every modding topic, (such as items, blocks, mobs, worldgen, etc.) and are pretty easy to follow, and Kaupenjoe always leaves the link to his GitHub repositories where you can view the code of that tutorial at your own pace as well as linking textures in the description of his videos for you to use. These forums are also quite good if you need help, though I have found that it sometimes takes a little while for a response but it is always worth the wait; from my experience the people on these forums have always been kind and helpful. There are also user-submitted tutorials that may be helpful as well.  Using GitHub to search up a certain class that you are wanting to use in your mod is also quite helpful, the video I have linked goes into more detail. I would also recommend planning out your mod before you make it to have a clearer idea of how you want your mod to be, including sketches and annotations are also a good idea for this. It has helped me make progress a lot quicker when programming as I already know how I want things to look/act.   I hope all this information helps!
    • I don't know what I did differently, but the error code changed to "Invalid signature for profile public key" so I set "enforce-secure-profile" to false since only my friend will be allowed to join anyway and then everything worked properly. Here's the logs anyway, but I hope the problem doesn't come back. https://paste.ee/p/Ri44L
    • I tried to look for similar issues here on the forum already and couldn't find a fix. Just people who didn't read the rules properly.
  • Topics

×
×
  • Create New...

Important Information

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