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

[solved][1.17.1] how to make Entity Models Register?


 Share

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
Link to comment
Share on other sites

  • 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
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

    • It doesn't work even if I remove every mod Please help
    • Hi, so I was making an item that sends info to the server to do some work, and I want the server to send the client back the results? How do I do that? Here is my code:   The snippet that sends the packet to the server SimpleChannelNetwork.CHANNEL.sendToServer(new CreateStructureCompass("fortress"));   The file that manage the traffic package io.github.bossmania.NetherandEndMaps.core.network; import io.github.bossmania.NetherandEndMaps.NetherandEndMaps; import io.github.bossmania.NetherandEndMaps.core.network.message.CreateStructureCompass; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; public class SimpleChannelNetwork { public static final String NETWORK_VERSION = "0.1.0"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(NetherandEndMaps.MOD_ID, "network"), () -> NETWORK_VERSION, version -> version.equals(NETWORK_VERSION), version -> version.equals(NETWORK_VERSION)); public static void init() { CHANNEL.registerMessage(0, CreateStructureCompass.class ,CreateStructureCompass::encode, CreateStructureCompass::decode, CreateStructureCompass::handle); } }   the code that handle the packet receive and where I want the server to send back a packet to the client package io.github.bossmania.NetherandEndMaps.core.network.message; import java.util.function.Supplier; import io.github.bossmania.NetherandEndMaps.common.items.TemporaryItem; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.gen.feature.structure.Structure; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.fml.network.NetworkEvent; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; public class CreateStructureCompass { public String structureType; public CreateStructureCompass() { } //create the constructor and store the structureType public CreateStructureCompass(String structureType) { this.structureType = structureType; } //encode the message public static void encode(CreateStructureCompass message, PacketBuffer buffer) { buffer.writeString(message.structureType); } //decode the message public static CreateStructureCompass decode(PacketBuffer buffer) { return new CreateStructureCompass(buffer.readString()); } //execute function when message is sent to server public static void handle(CreateStructureCompass message, Supplier<NetworkEvent.Context> contextSupplier) { NetworkEvent.Context context = contextSupplier.get(); context.enqueueWork(() -> { //get the player and the server ServerPlayerEntity player = context.getSender(); ServerWorld SEWorld = player.getServerWorld(); //get the location of the structure BlockPos structureLocation = SEWorld.func_241117_a_(Structure.FORTRESS, player.getPosition(),100, false); //this is where I want the server to send structureLocation back to the player }); context.setPacketHandled(true); } }  
    • I cannot get an instance of MC Forge to run with either the vanilla launcher or GDLauncher, yet vanilla MC and Fabric MC work fine in both.  I am running the latest versions of everything, and no 1.18-compatible version of Forge will launch even though they all install without fail. Using the vanilla launcher I get exit code 0 and the following logs: Debug log Latest log With GDLauncher I get the following console output:  
    • In 1.15 and before, you could get the item being held/dragged by the cursor using PlayerInventory#getItemStack. This no longer seems to be the case. How do we do this now?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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