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

Trouble registering packets


Recommended Posts

 

I keep getting this message

"[19:05:18] [Render thread/WARN] [minecraft/ClientPlayNetHandler]: Unknown custom packet identifier: morecontent:main"

when i send a packet instead of doing whatever that packet should do.

 

here are the classes

 

PacketHandler and the packet

 

public class PacketHandler {
    private static final String PROTOCOL_VERSION = "1";
    public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
            new ResourceLocation(MoreContent.MOD_ID, "main"),
            () -> PROTOCOL_VERSION,
            PROTOCOL_VERSION::equals,
            PROTOCOL_VERSION::equals
    );


    public static void register() {
        int ID = 0;
        INSTANCE.registerMessage(++ID, AnimationPacket.class, AnimationPacket::encode, AnimationPacket::new, AnimationPacket::handle);
    }
}
public class AnimationPacket {
    private int entityId;
    private int animationIndex;



    AnimationPacket(final PacketBuffer packetBuffer) {
        this.entityId = packetBuffer.readInt();
        this.animationIndex = packetBuffer.readInt();
    }

    public AnimationPacket(int entityId, int index) {
        this.entityId = entityId;
        this.animationIndex = index;
    }

    void encode(final PacketBuffer packetBuffer) {
        packetBuffer.writeInt(this.entityId);
        packetBuffer.writeInt(this.animationIndex);
    }


    public static void handle(AnimationPacket msg, Supplier<NetworkEvent.Context> ctx) {
        NetworkEvent.Context context = ctx.get();
        if (context.getDirection().getReceptionSide() == LogicalSide.SERVER) {
            ctx.get().enqueueWork(() -> {
                Entity entity = Objects.requireNonNull(context.getSender()).world.getEntityByID(msg.entityId);
                if(entity instanceof AnimatedEntity) {
                    
                    ((AnimatedEntity) entity).spawnExplosionParticle();
                }
                });
                ctx.get().setPacketHandled(true);
        }
    }
}

 

Main

@Mod("morecontent")
@Mod.EventBusSubscriber(
        modid = "morecontent",
        bus = Mod.EventBusSubscriber.Bus.MOD
)
public class MoreContent {
    public static MoreContent INSTANCE;
    public static final String MOD_ID = "morecontent";
    public static final Logger LOGGER = LogManager.getLogger("morecontent");

    public MoreContent() {
        INSTANCE = this;
        MinecraftForge.EVENT_BUS.register(this);
        PacketHandler.register();
        new RegistryEvents();

        MinecraftForge.EVENT_BUS.register(EventHandler.class);

    }

    @SubscribeEvent
    public void setupCommon(FMLCommonSetupEvent event) {
        DeferredWorkQueue.runLater(() -> {
            RegistryEvents.addBiomeTypes();
            RegistryEvents.registerBiomesToDictionary();

        });
    }

    @SubscribeEvent
    public static void clientSetup(FMLClientSetupEvent event) {
        RenderHandler.registerEntityRenders();
        RenderHandler.registerBlockRenders();
    }
}

 

this is how i send the packet:

PacketHandler.INSTANCE.send(PacketDistributor.ALL.noArg(), new AnimationPacket(this.getEntityId(), 1));

Link to post
Share on other sites

Updates

 

I noticed that i had to register them in the FMLCommonSetupEvent but now when i send a packet i get a crash along with this message

 

[19:51:22] [Server thread/ERROR] [ne.mi.fm.ne.NetworkRegistry/NETREGISTRY]: Attempted to register channel morecontent:main even though registry phase is over


"[19:51:22] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
java.lang.ExceptionInInitializerError: null

Edited by epicMinecrafter666Xx
Link to post
Share on other sites

This:

35 minutes ago, epicMinecrafter666Xx said:

@Mod.EventBusSubscriber( modid = "morecontent", bus = Mod.EventBusSubscriber.Bus.MOD )

This:

35 minutes ago, epicMinecrafter666Xx said:

MinecraftForge.EVENT_BUS.register(this);

And this:

35 minutes ago, epicMinecrafter666Xx said:

MinecraftForge.EVENT_BUS.register(EventHandler.class);

 

 

All do the same thing (the first two literally do except for different busses and the only event methods you have are all FORGE bus events; the second does the same thing, but to a different class).

Pick one.

 

Then there's this:

36 minutes ago, epicMinecrafter666Xx said:

new RegistryEvents();

Which either also does the same thing or does nothing (you didn't share that class). And is either way confusing.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

RegistryEvents is where i register the blocks, items and biomes

 

@Mod.EventBusSubscriber(
        bus = Bus.MOD
)
public class RegistryEvents {


    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MoreContent.MOD_ID);
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MoreContent.MOD_ID);
    public static final DeferredRegister<Biome> BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, MoreContent.MOD_ID);

    @SubscribeEvent
    public static void onEntityRegistry(Register<EntityType<?>> event) {
        ModEntityTypes.register(event.getRegistry());
    }


    public RegistryEvents() {
        BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        BIOMES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

    //*************************ITEMS****************************************************************//

     public static final RegistryObject<Item> ENDER_BEAST_ARCHER = ITEMS.register("ender_beast_archer_spawn_egg", () -> new SpawnEggItem(ModEntityTypes.ENDERBEASTARCHER, 3286365, 4859178, (new Item.Properties()).group(ItemGroup.MISC)));

    //BLOCKITEMS

    public static final RegistryObject<Item> FIERCE_SAND_ITEM = ITEMS.register("fierce_sand", () -> new BlockItem(RegistryEvents.FIERCE_SAND.get(), new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)));
    public static final RegistryObject<Item> FIERCE_SANDSTONE_ITEM = ITEMS.register("fierce_sandstone", () -> new BlockItem(RegistryEvents.FIERCE_SANDSTONE.get(), new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)));
    public static final RegistryObject<Item> FOSSILS_ITEM = ITEMS.register("fossils", () -> new BlockItem(RegistryEvents.FOSSILS.get(), new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)));
    public static final RegistryObject<Item> ERODED_STONE_ITEM = ITEMS.register("eroded_stone", () -> new BlockItem(RegistryEvents.ERODED_STONE.get(), new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)));

    public static final RegistryObject<Item> DEAD_GRASS_ITEM = ITEMS.register("dead_grass", () -> new BlockItem(RegistryEvents.DEAD_GRASS.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));
    public static final RegistryObject<Item> DESERTS_HOPE_ITEM = ITEMS.register("deserts_hope", () -> new BlockItem(RegistryEvents.DESERTS_HOPE.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));

    public static final RegistryObject<Item> SPIKED_VINE_ITEM = ITEMS.register("spiked_vine", () -> new BlockItem(RegistryEvents.SPIKED_VINE.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));
    public static final RegistryObject<Item> SPIKY_FRUIT_ITEM = ITEMS.register("spiky_fruit", () -> new Item(new Item.Properties().group(ItemGroup.FOOD).food(ModFoods.SPIKY_FRUIT)));
    public static final RegistryObject<Item> GOLDEN_SPIKY_FRUIT_ITEM = ITEMS.register("golden_spiky_fruit", () -> new Item(new Item.Properties().group(ItemGroup.FOOD).food(ModFoods.GOLDEN_SPIKY_FRUIT)));


    /////
    public static final RegistryObject<Item> LARGE_ACACIA_TORCH_ITEM = ITEMS.register("large_acacia_torch", () -> new BlockItem(RegistryEvents.LARGE_ACACIA_TORCH.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));
    public static final RegistryObject<Item> LARGE_BIRCH_TORCH_ITEM = ITEMS.register("large_birch_torch", () -> new BlockItem(RegistryEvents.LARGE_BIRCH_TORCH.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));
    public static final RegistryObject<Item> LARGE_DARK_OAK_TORCH_ITEM = ITEMS.register("large_dark_oak_torch", () -> new BlockItem(RegistryEvents.LARGE_DARK_OAK_TORCH.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));
    public static final RegistryObject<Item> LARGE_JUNGLE_TORCH_ITEM = ITEMS.register("large_jungle_torch", () -> new BlockItem(RegistryEvents.LARGE_JUNGLE_TORCH.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));
    public static final RegistryObject<Item> LARGE_OAK_TORCH_ITEM = ITEMS.register("large_oak_torch", () -> new BlockItem(RegistryEvents.LARGE_OAK_TORCH.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));
    public static final RegistryObject<Item> LARGE_SPRUCE_TORCH_ITEM = ITEMS.register("large_spruce_torch", () -> new BlockItem(RegistryEvents.LARGE_SPRUCE_TORCH.get(), new Item.Properties().group(ItemGroup.DECORATIONS)));


    //*************************BLOCKS***************************************************************//

    public static final RegistryObject<Block> FIERCE_SAND = BLOCKS.register("fierce_sand", () -> new SandBlock(16760677, Block.Properties.create(Material.SAND, MaterialColor.SAND).hardnessAndResistance(0.5F).harvestTool(ToolType.SHOVEL).sound(SoundType.SAND)));
    public static final RegistryObject<Block> FIERCE_SANDSTONE = BLOCKS.register("fierce_sandstone", () -> new Block(Block.Properties.create(Material.ROCK, MaterialColor.SAND).hardnessAndResistance(0.9F).harvestTool(ToolType.PICKAXE).sound(SoundType.STONE)));
    public static final RegistryObject<Block> FOSSILS = BLOCKS.register("fossils", () -> new Block(Block.Properties.create(Material.ROCK, MaterialColor.DIRT).hardnessAndResistance(1.0F).harvestTool(ToolType.PICKAXE).sound(SoundType.STONE)));
    public static final RegistryObject<Block> ERODED_STONE = BLOCKS.register("eroded_stone", () -> new Block(Block.Properties.create(Material.ROCK, MaterialColor.DIRT).hardnessAndResistance(1.0F).harvestTool(ToolType.PICKAXE).sound(SoundType.STONE)));

    public static final RegistryObject<Block> SPIKED_VINE = BLOCKS.register("spiked_vine", () -> new SpikedVineBlock(Block.Properties.create(Material.PLANTS, MaterialColor.GRASS).hardnessAndResistance(0.5F).harvestTool(ToolType.AXE).sound(SoundType.PLANT)));
    public static final RegistryObject<Block> SPIKY_FRUIT = BLOCKS.register("spiky_fruit", () -> new SpikyFruitBlock(Block.Properties.create(Material.PLANTS, MaterialColor.ORANGE_TERRACOTTA).hardnessAndResistance(0.5F).harvestTool(ToolType.AXE).sound(SoundType.PLANT)));
    public static final RegistryObject<Block> DEAD_GRASS = BLOCKS.register("dead_grass", () -> new DeserticBushBlock(Block.Properties.create(Material.PLANTS, MaterialColor.GOLD).zeroHardnessAndResistance().sound(SoundType.PLANT).doesNotBlockMovement()));
    public static final RegistryObject<Block> DESERTS_HOPE = BLOCKS.register("deserts_hope", () -> new FlowerBlock(Effects.REGENERATION, 8, Block.Properties.create(Material.PLANTS).zeroHardnessAndResistance().sound(SoundType.PLANT).doesNotBlockMovement()));

    ////
    public static final RegistryObject<Block> POTTED_DESERTS_HOPE = BLOCKS.register("potted_deserts_hope", () -> new FlowerPotBlock(RegistryEvents.DESERTS_HOPE.get(), Block.Properties.create(Material.MISCELLANEOUS).zeroHardnessAndResistance().notSolid()));

    public static final RegistryObject<Block> LARGE_ACACIA_TORCH = BLOCKS.register("large_acacia_torch", () -> new LargeTorchBlock(Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0.75F).sound(SoundType.WOOD)));
    public static final RegistryObject<Block> LARGE_BIRCH_TORCH = BLOCKS.register("large_birch_torch", () -> new LargeTorchBlock(Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0.75F).sound(SoundType.WOOD)));
    public static final RegistryObject<Block> LARGE_DARK_OAK_TORCH = BLOCKS.register("large_dark_oak_torch", () -> new LargeTorchBlock(Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0.75F).sound(SoundType.WOOD)));
    public static final RegistryObject<Block> LARGE_JUNGLE_TORCH = BLOCKS.register("large_jungle_torch", () -> new LargeTorchBlock(Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0.75F).sound(SoundType.WOOD)));
    public static final RegistryObject<Block> LARGE_OAK_TORCH = BLOCKS.register("large_oak_torch", () -> new LargeTorchBlock(Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0.75F).sound(SoundType.WOOD)));
    public static final RegistryObject<Block> LARGE_SPRUCE_TORCH = BLOCKS.register("large_spruce_torch", () -> new LargeTorchBlock(Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0.75F).sound(SoundType.WOOD)));

    
    ////////BIOMES/////////
    
    public static final RegistryObject<Biome> RAMMERS_VALLEY = BIOMES.register("rammers_valley", RammersValleyBiome::new);

    public static void registerBiomesToDictionary() {
        BiomeManager.addBiome(BiomeManager.BiomeType.WARM, new BiomeManager.BiomeEntry(RAMMERS_VALLEY.get(), 30));
    }

    public static void addBiomeTypes() {
        BiomeDictionary.addTypes(RAMMERS_VALLEY.get(), BiomeDictionary.Type.DRY, BiomeDictionary.Type.SANDY, BiomeDictionary.Type.OVERWORLD);
    }
}

 

apparently if i delete new RegistryEvents();  Minecraft throws me this: More Content (more content) encountered an error during the load_registries event phase

 

the other thing you pointed out were infact useless.

 

@Mod("morecontent")
@Mod.EventBusSubscriber(modid = "morecontent", bus = Mod.EventBusSubscriber.Bus.MOD)
public class MoreContent {
    public static MoreContent INSTANCE;
    public static final String MOD_ID = "morecontent";
    public MoreContent() {
        INSTANCE = this;
        new RegistryEvents();
    }

    @SubscribeEvent
    public void setupCommon(FMLCommonSetupEvent event) {
        PacketHandler.register();
        DeferredWorkQueue.runLater(() -> {
            RegistryEvents.addBiomeTypes();
            RegistryEvents.registerBiomesToDictionary();

        });
    }

    @SubscribeEvent
    public static void clientSetup(FMLClientSetupEvent event) {
        RenderHandler.registerEntityRenders();
        RenderHandler.registerBlockRenders();
    }
}

 

i registered the packets on FMLCommonSetup and i get a crash when i use a packet along with this

 

[19:51:22] [Server thread/ERROR] [ne.mi.fm.ne.NetworkRegistry/NETREGISTRY]: Attempted to register channel morecontent:main even though registry phase is over


"[19:51:22] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
java.lang.ExceptionInInitializerError: null

 

Link to post
Share on other sites

I understand your issue with with the networking. However I'm pointing out that you're hurling all of your classes at the event bus four different ways and you don't need to do that.

 

And I was right:

1 hour ago, epicMinecrafter666Xx said:

BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());

ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

BIOMES.register(FMLJavaModLoadingContext.get().getModEventBus());

You're doing more registration, yet another way.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Understood, and I'll go check that out. Thank you so much!
    • This. The reason for this is that DeferredRegister relies on static initializers. If you put your RegistryObjects in some random class it is not guaranteed that that class is actually initialized by the time your DeferredRegister is. Hence: Put the DeferredRegister and its entries in the same class. @ObjectHolder is explained here: https://mcforge.readthedocs.io/en/latest/concepts/registries/#using-objectholder
    • Okay, thanks for the help! A few questions. BLOCKS and ITEMS are in the same class as each other- it's called 'registry'. (forgot to capitalize, oops- I'll fix that momentarily.) What exactly shouldn't be in separate classes? Are you saying that my actual RegistryObjects (the individual blocks, items, etc.) should all be in the same class? Or that the DeferredRegisters should all be in the same class? Or that all the RegistryObject<Block>s should be in the same class as the DeferredRegister<Block>, and the RegistryObject<Item>s should be in the same class as the DeferredRegister<Item>, but those two classes don't necessarily have to be the same? What is @ObjectHolder, what does it do, and where can I go to learn more? (That is, assuming it's a Forge thing. If it's a Java thing I don't know, say so and I'll go research it elsewhere- I understand and respect that this forum isn't a place to look for Java help.)
    • First of all the BLOCKS and ITEMS fields (i.e. your DeferredRegister instances) should not be in a separate class. Put them in the same class or you will have issues. No, you cannot, because then you defeat the entire purpose of DeferredRegister. You must create your registry objects (blocks, items, etc.) in the registry event. DeferredRegister manages this for you. If you don't want this, you can also manually subscribe to RegistryEvent and create and register your things there. You can then use @ObjectHolder to obtain the instances for your registry entries. You can also mix and match these if you so choose - you can have @ObjectHolder annotated fields and things registered by DeferredRegister will still end up there and equally you can register things manually in RegistryEvent and create your own RegistryObject (just call the of method) which you can then use to access them. But what you cannot do is create registry objects (i.e. blocks and items) outside registry events.
    • From my understanding, all of my blocks, items, and whatnot should be registered like this: public static final RegistryObject<Block> CRASH_PAD = registry.BLOCKS.register("crash_pad", () -> new CrashPadBlock(AbstractBlock.Properties.of(Material.CLAY, MaterialColor.GRASS).friction(0.8F).sound(SoundType.SLIME_BLOCK).noOcclusion())); public static final RegistryObject<Item> ALCHEMICAL_FLASK = registry.ITEMS.register("alchemical_flask", () -> new Item(new Item.Properties().tab(ItemGroup.TAB_MATERIALS))); If I then wished to refer to the crash_pad Block, or the alchemical_flask Item, do I have to refer to them as 'registry.CRASH_PAD.get()' and 'registry.ALCHEMICAL_FLASK.get()'? This seems a bit roundabout. Can I define the blocks as Blocks and the items as Items before creating and registering RegistryObject<T>s from them, or do I have to always get the blocks and items from their RegistryObjects?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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