Jump to content

Recommended Posts

Posted

How would i go about sending a packet when a certain event occurs, it crashes every time

 

Main mod:

 

package rainbow.summonercraft;

 

 

import net.minecraft.client.settings.KeyBinding;

import net.minecraftforge.common.MinecraftForge;

import net.minecraftforge.fml.client.registry.ClientRegistry;

import net.minecraftforge.fml.common.FMLCommonHandler;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.SidedProxy;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.network.NetworkRegistry;

import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;

import net.minecraftforge.fml.relauncher.Side;

import org.apache.logging.log4j.LogManager;

import org.apache.logging.log4j.Logger;

import org.lwjgl.input.Keyboard;

import rainbow.summonercraft.init.ModBlocks;

import rainbow.summonercraft.init.ModItems;

import rainbow.summonercraft.proxy.CommonProxy;

 

@Mod(modid = ModInfo.modid, name = ModInfo.modname, version = ModInfo.version)

public class SummonCraft {

 

    @SidedProxy(clientSide = ModInfo.clientproxy,

            serverSide = ModInfo.serverproxy)

    public static CommonProxy proxy;

 

    public static final Logger logger = LogManager.getLogger(ModInfo.modid);

    public static SimpleNetworkWrapper network;

 

    @Mod.EventHandler

    public void preInit(FMLPreInitializationEvent event) {

 

        ModBlocks.init();

        ModBlocks.register();

        ModItems.init();

        ModItems.register();

 

 

        network = NetworkRegistry.INSTANCE.newSimpleChannel(ModInfo.modid);

        network.registerMessage(SummonInventoryPacket.SummonInventoryPacketHandler.class, SummonInventoryPacket.class, 0, Side.SERVER);

 

        FMLCommonHandler.instance().bus().register(new ModdedEventHandler());

        proxy.init();

    }

 

    @Mod.EventHandler

    public void init(FMLInitializationEvent event) {

 

        proxy.registerRenders();

    }

 

    @Mod.EventHandler

    public void postInit(FMLPostInitializationEvent event) {

 

    }

}

 

 

 

Packet Class:

 

package rainbow.summonercraft;

 

import io.netty.buffer.ByteBuf;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.IThreadListener;

import net.minecraft.world.WorldServer;

import net.minecraftforge.fml.common.network.ByteBufUtils;

import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;

import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

 

public class SummonInventoryPacket implements IMessage {

 

    private static ItemStack itemstack;

    private static EntityPlayer player;

 

    public SummonInventoryPacket() {

    }

 

    public SummonInventoryPacket(ItemStack itemstack, EntityPlayer player) {

        this.itemstack = itemstack;

        this.player = player;

    }

 

    @Override

    public void fromBytes(ByteBuf buf) {

 

    }

 

    @Override

    public void toBytes(ByteBuf buf) {

 

    }

 

    public static class SummonInventoryPacketHandler implements IMessageHandler<SummonInventoryPacket, IMessage> {

 

        @Override

        public IMessage onMessage(SummonInventoryPacket message, MessageContext ctx) {

            IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj;

            mainThread.addScheduledTask(new Runnable() {

                @Override

                public void run() {

                    if (itemstack == null) {

 

                        if (player.getHeldItem() == null) {

                            player.addChatMessage(new ChatComponentText("[summonercraft] You do not have an item in your hand!"));

                            return;

                        }

                        itemstack = player.getHeldItem();

                        player.getHeldItem().setItem(null);

                        player.addChatMessage(new ChatComponentText("[summonercraft] Your item has been desposited"));

                    } else if (itemstack != null) {

 

                        if (player.getHeldItem() == null) {

 

                            player.getHeldItem().setItem(itemstack.getItem());

                            itemstack = null;

                            player.addChatMessage(new ChatComponentText("[summonercraft] Your item has been summoned!"));

                            return;

                        }

                        ItemStack stack = player.getHeldItem();

 

                        player.getHeldItem().setItem(itemstack.getItem());

                        itemstack = stack;

                        player.addChatMessage(new ChatComponentText("[summonercraft] Your item has been exchanged!"));

                    }

                }

            });

            return null;

        }

    }

}

 

 

Event Handler:

 

package rainbow.summonercraft;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.settings.KeyBinding;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.IChatComponent;

import net.minecraftforge.fml.common.eventhandler.EventPriority;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.minecraftforge.fml.common.gameevent.InputEvent;

import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import rainbow.summonercraft.proxy.ClientProxy;

 

public class ModdedEventHandler {

 

    public static ItemStack itemstack;

 

    @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)

    public void onEvent(InputEvent.KeyInputEvent event) {

 

        KeyBinding[] keyBindings = ClientProxy.keyBindings;

        EntityPlayer p = Minecraft.getMinecraft().thePlayer;

 

        if (keyBindings[0].isPressed()) {

 

            SummonCraft.network.registerMessage(SummonInventoryPacket.SummonInventoryPacketHandler.class, SummonInventoryPacket.class, 0, Side.CLIENT);

        }

 

    }

}

 

 

 

Crash Log:

 

---- Minecraft Crash Report ----

// Oops.

 

Time: 7/14/15 12:14 AM

Description: Unexpected error

 

java.lang.IllegalArgumentException: Duplicate handler name: rainbow.summonercraft.SummonInventoryPacket$SummonInventoryPacketHandler

at io.netty.channel.DefaultChannelPipeline.checkDuplicateName(DefaultChannelPipeline.java:898)

at io.netty.channel.DefaultChannelPipeline.addAfter(DefaultChannelPipeline.java:191)

at io.netty.channel.DefaultChannelPipeline.addAfter(DefaultChannelPipeline.java:183)

at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.addClientHandlerAfter(SimpleNetworkWrapper.java:153)

at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:140)

at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:106)

at rainbow.summonercraft.ModdedEventHandler.onEvent(ModdedEventHandler.java:29)

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_ModdedEventHandler_onEvent_KeyInputEvent.invoke(.dynamic)

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55)

at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at net.minecraftforge.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:581)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:2041)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087)

at net.minecraft.client.Minecraft.run(Minecraft.java:376)

at net.minecraft.client.main.Main.main(Main.java:117)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at io.netty.channel.DefaultChannelPipeline.checkDuplicateName(DefaultChannelPipeline.java:898)

at io.netty.channel.DefaultChannelPipeline.addAfter(DefaultChannelPipeline.java:191)

at io.netty.channel.DefaultChannelPipeline.addAfter(DefaultChannelPipeline.java:183)

at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.addClientHandlerAfter(SimpleNetworkWrapper.java:153)

at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:140)

at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:106)

at rainbow.summonercraft.ModdedEventHandler.onEvent(ModdedEventHandler.java:29)

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_ModdedEventHandler_onEvent_KeyInputEvent.invoke(.dynamic)

at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55)

at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at net.minecraftforge.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:581)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityPlayerSP['Player185'/350, l='MpServer', x=-255.31, y=71.00, z=259.63]]

Chunk stats: MultiplayerChunkCache: 615, 615

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: -228.00,64.00,244.00 - World: (-228,64,244), Chunk: (at 12,4,4 in -15,15; contains blocks -240,0,240 to -225,255,255), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 8288 game time, 6000 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 94 total; [EntityZombie['Zombie'/256, l='MpServer', x=-174.00, y=23.00, z=197.41], EntitySpider['Spider'/257, l='MpServer', x=-174.50, y=41.00, z=201.50], EntityZombie['Zombie'/49, l='MpServer', x=-320.72, y=29.46, z=203.69], EntityCreeper['Creeper'/50, l='MpServer', x=-330.53, y=26.00, z=194.97], EntitySpider['Spider'/52, l='MpServer', x=-323.31, y=36.00, z=202.69], EntityCreeper['Creeper'/53, l='MpServer', x=-333.44, y=34.00, z=207.56], EntityEnderman['Enderman'/55, l='MpServer', x=-326.28, y=34.00, z=211.41], EntitySheep['Sheep'/56, l='MpServer', x=-327.38, y=82.00, z=222.44], EntityZombie['Zombie'/57, l='MpServer', x=-326.09, y=18.00, z=226.47], EntitySheep['Sheep'/58, l='MpServer', x=-323.53, y=78.00, z=237.44], EntityRabbit['Rabbit'/59, l='MpServer', x=-321.50, y=74.00, z=234.88], EntitySheep['Sheep'/60, l='MpServer', x=-328.34, y=77.00, z=241.56], EntityRabbit['Rabbit'/61, l='MpServer', x=-330.59, y=74.00, z=243.63], EntitySheep['Sheep'/62, l='MpServer', x=-324.38, y=74.00, z=254.22], EntitySheep['Sheep'/63, l='MpServer', x=-326.88, y=75.00, z=246.84], EntityRabbit['Rabbit'/64, l='MpServer', x=-326.31, y=74.00, z=263.31], EntitySheep['Sheep'/65, l='MpServer', x=-330.88, y=73.00, z=269.19], EntitySkeleton['Skeleton'/66, l='MpServer', x=-323.44, y=64.00, z=265.91], EntityRabbit['Rabbit'/67, l='MpServer', x=-320.63, y=73.00, z=271.38], EntityBat['Bat'/79, l='MpServer', x=-305.91, y=30.10, z=198.25], EntityBat['Bat'/80, l='MpServer', x=-309.75, y=31.10, z=201.47], EntitySkeleton['Skeleton'/81, l='MpServer', x=-312.66, y=49.00, z=205.16], EntityBat['Bat'/82, l='MpServer', x=-311.34, y=24.00, z=214.19], EntitySpider['Spider'/83, l='MpServer', x=-313.28, y=58.00, z=211.28], EntityBat['Bat'/84, l='MpServer', x=-314.25, y=29.10, z=230.25], EntitySheep['Sheep'/85, l='MpServer', x=-315.53, y=74.00, z=241.31], EntityRabbit['Rabbit'/86, l='MpServer', x=-315.41, y=72.00, z=249.44], EntitySheep['Sheep'/87, l='MpServer', x=-312.38, y=74.00, z=265.81], EntitySheep['Sheep'/88, l='MpServer', x=-316.91, y=73.00, z=267.63], EntityCreeper['Creeper'/95, l='MpServer', x=-289.16, y=36.00, z=189.22], EntityRabbit['Rabbit'/96, l='MpServer', x=-305.63, y=71.00, z=183.25], EntityZombie['Zombie'/98, l='MpServer', x=-302.97, y=59.00, z=207.19], EntityZombie['Zombie'/99, l='MpServer', x=-302.00, y=60.00, z=197.00], EntityZombie['Zombie'/100, l='MpServer', x=-298.41, y=60.00, z=200.50], EntitySkeleton['Skeleton'/101, l='MpServer', x=-303.50, y=60.00, z=194.50], EntityRabbit['Rabbit'/102, l='MpServer', x=-299.47, y=71.00, z=226.84], EntitySheep['Sheep'/103, l='MpServer', x=-299.13, y=73.00, z=246.16], EntityRabbit['Rabbit'/114, l='MpServer', x=-285.59, y=65.00, z=186.44], EntityCreeper['Creeper'/115, l='MpServer', x=-284.06, y=32.00, z=201.41], EntityPlayerSP['Player185'/350, l='MpServer', x=-255.31, y=71.00, z=259.63], EntityCreeper['Creeper'/116, l='MpServer', x=-284.06, y=33.00, z=202.53], EntityRabbit['Rabbit'/117, l='MpServer', x=-276.66, y=70.00, z=195.41], EntityZombie['Zombie'/118, l='MpServer', x=-274.31, y=30.00, z=218.28], EntitySkeleton['Skeleton'/119, l='MpServer', x=-278.50, y=31.00, z=218.50], EntityCreeper['Creeper'/120, l='MpServer', x=-275.38, y=30.00, z=218.34], EntityCreeper['Creeper'/121, l='MpServer', x=-282.28, y=31.00, z=212.84], EntityCreeper['Creeper'/122, l='MpServer', x=-272.94, y=33.00, z=217.38], EntitySkeleton['Skeleton'/123, l='MpServer', x=-284.53, y=61.00, z=224.88], EntitySkeleton['Skeleton'/124, l='MpServer', x=-287.75, y=59.00, z=231.09], EntityRabbit['Rabbit'/125, l='MpServer', x=-284.50, y=70.00, z=231.44], EntityItem['item.tile.flower1.dandelion'/126, l='MpServer', x=-272.22, y=70.00, z=261.56], EntityRabbit['Rabbit'/127, l='MpServer', x=-272.59, y=76.00, z=289.63], EntitySpider['Spider'/128, l='MpServer', x=-280.72, y=26.00, z=330.03], EntitySheep['Sheep'/138, l='MpServer', x=-265.69, y=69.00, z=207.41], EntitySheep['Sheep'/139, l='MpServer', x=-257.81, y=67.00, z=194.34], EntitySheep['Sheep'/140, l='MpServer', x=-266.31, y=69.00, z=195.19], EntityCreeper['Creeper'/141, l='MpServer', x=-263.38, y=29.00, z=213.94], EntityZombie['Zombie'/142, l='MpServer', x=-266.50, y=29.00, z=215.50], EntityZombie['Zombie'/143, l='MpServer', x=-264.44, y=29.00, z=215.03], EntityBat['Bat'/144, l='MpServer', x=-270.88, y=24.05, z=227.68], EntityBat['Bat'/145, l='MpServer', x=-279.59, y=26.77, z=239.24], EntityBat['Bat'/146, l='MpServer', x=-268.75, y=25.10, z=250.44], EntityItem['item.tile.flower2.poppy'/147, l='MpServer', x=-256.34, y=75.00, z=279.59], EntityRabbit['Rabbit'/148, l='MpServer', x=-258.69, y=74.00, z=298.47], EntityRabbit['Rabbit'/149, l='MpServer', x=-265.06, y=72.00, z=334.75], EntitySheep['Sheep'/154, l='MpServer', x=-251.59, y=67.00, z=187.31], EntityRabbit['Rabbit'/155, l='MpServer', x=-257.41, y=67.00, z=203.41], EntitySkeleton['Skeleton'/156, l='MpServer', x=-253.72, y=32.00, z=223.19], EntitySkeleton['Skeleton'/157, l='MpServer', x=-252.94, y=34.00, z=224.41], EntitySkeleton['Skeleton'/158, l='MpServer', x=-254.69, y=32.00, z=224.69], EntityRabbit['Rabbit'/159, l='MpServer', x=-241.23, y=72.22, z=273.02], EntityItem['item.tile.grass'/163, l='MpServer', x=-227.66, y=67.00, z=251.88], EntityRabbit['Rabbit'/164, l='MpServer', x=-232.50, y=69.00, z=287.84], EntityRabbit['Rabbit'/165, l='MpServer', x=-236.28, y=69.00, z=303.56], EntitySkeleton['Skeleton'/185, l='MpServer', x=-219.56, y=13.00, z=200.16], EntitySkeleton['Skeleton'/186, l='MpServer', x=-213.44, y=15.00, z=194.56], EntityRabbit['Rabbit'/187, l='MpServer', x=-213.50, y=70.00, z=262.59], EntityCreeper['Creeper'/208, l='MpServer', x=-202.00, y=18.00, z=191.63], EntitySpider['Spider'/209, l='MpServer', x=-205.13, y=16.00, z=188.69], EntitySkeleton['Skeleton'/210, l='MpServer', x=-194.53, y=19.00, z=184.88], EntityCreeper['Creeper'/211, l='MpServer', x=-202.31, y=16.00, z=190.59], EntityRabbit['Rabbit'/212, l='MpServer', x=-194.19, y=74.00, z=240.47], EntityEnderman['Enderman'/213, l='MpServer', x=-208.72, y=29.00, z=332.28], EntityZombie['Zombie'/214, l='MpServer', x=-201.50, y=31.00, z=333.50], EntityZombie['Zombie'/231, l='MpServer', x=-191.50, y=18.00, z=185.50], EntityZombie['Zombie'/234, l='MpServer', x=-182.75, y=21.00, z=194.44], EntityZombie['Zombie'/235, l='MpServer', x=-179.88, y=46.00, z=196.63], EntityRabbit['Rabbit'/236, l='MpServer', x=-190.28, y=76.00, z=234.97], EntityRabbit['Rabbit'/237, l='MpServer', x=-181.31, y=75.00, z=258.25], EntityZombie['Zombie'/238, l='MpServer', x=-184.72, y=25.24, z=308.69], EntityZombie['Zombie'/239, l='MpServer', x=-182.13, y=25.00, z=333.28], EntityRabbit['Rabbit'/240, l='MpServer', x=-188.44, y=70.00, z=324.44], EntityBat['Bat'/252, l='MpServer', x=-179.04, y=39.55, z=181.57], EntityBat['Bat'/254, l='MpServer', x=-178.58, y=22.91, z=197.51]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:392)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2614)

at net.minecraft.client.Minecraft.run(Minecraft.java:405)

at net.minecraft.client.main.Main.main(Main.java:117)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

 

-- System Details --

Details:

Minecraft Version: 1.8

Operating System: Windows 8.1 (amd64) version 6.3

Java Version: 1.8.0_45, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 626134752 bytes (597 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 5, tcache: 0, allocated: 13, tallocated: 95

FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1450 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1450.jar)

UCHIJAAAA Forge{11.14.3.1450} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1450.jar)

UCHIJAAAA summonercraft{1.0} [summonercraft] (Summonercraft)

Loaded coremods (and transformers):

GL info: ' Vendor: 'Intel' Version: '4.2.0 - Build 10.18.10.3412' Renderer: 'Intel® HD Graphics 4400'

Launched Version: 1.8

LWJGL: 2.9.1

OpenGL: Intel® HD Graphics 4400 GL version 4.2.0 - Build 10.18.10.3412, Intel

GL Caps: Using GL 1.3 multitexturing.

Using GL 1.3 texture combiners.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Shaders are available because OpenGL 2.1 is supported.

VBOs are available because OpenGL 1.5 is supported.

 

Using VBOs: No

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: English (US)

Profiler Position: N/A (disabled)

 

Posted

You are registering your packet again on the key press, instead of sending it - this is waaaaaay wrong. Only ever register your packet ONCE.

 

To send it, you need to use your simple network wrapper instance:

// this sends to the server, obviously
SummonCraft.network.sendToServer(new YourMessageClass(...));

 

Oh! Thanks!!!!

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 know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
    • Hi here is an update. I was able to fix the code so my mod does not crash Minecraft. Please understand that I am new to modding but I honestly am having a hard time understanding how anyone can get this to work without having extensive programming and debugging experience as well as searching across the Internet, multiple gen AI bots (claude, grok, openai), and examining source code hidden in the gradle directory and in various github repositories. I guess I am wrong because clearly there are thousands of mods so maybe I am just a newbie. Ok, rant over, here is a step by step summary so others can save the 3 days it took me to figure this out.   1. First, I am using forge 54.1.0 and Minecraft 1.21.4 2. I am creating a mod to add a shotgun to Minecraft 3. After creating the mod and compiling it, I installed the .jar file to the proper directory in Minecraft and used 1.21.4-forge-54.1.0 4. The mod immediately crashed with the error: Caused by: java.lang.NullPointerException: Item id not set 5. Using the stack trace, I determined that the Exception was being thrown from the net.minecraft.world.item.Item.Properties class 6. It seems that there are no javadocs for this class, so I used IntelliJ which was able to provide a decompiled version of the class, which I then examined to see the source of the error. Side question: Are there javadocs? 7. This method, specifically, was the culprit: protected String effectiveDescriptionId() {      return this.descriptionId.get(Objects.requireNonNull(this.id, "Item id not set"));  } 8. Now my quest was to determine how to set this.id. Looking at the same source file, I determined there was another method:  public Item.Properties setId(ResourceKey<Item> pId) {             this.id = pId;             return this;   } 9. So now, I need to figure out how to call setId(). This required working backwards a bit. Starting from the constructor, I stubbed out the variable p which is of type Item.Properties public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); Rather than putting this all on one line, I split it up for readability like this: private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); Here is was the missing function, setId(), which takes a type of ResourceKey<Item>. My next problem is that due to the apparent lack of documentation (I tried searching the docs on this site) I could not determine the full import path to ResourceKey. I did some random searching on the Internet and stumbled across a Github repository which gave two clues: import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; Then I created the rk variable like this: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); And now putting it all together in order: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); This compiled and the mod no longer crashes. I still have more to do on it, but hopefully this will save someone hours. I welcome any feedback and if I missed some obvious modding resource or tutorial that has this information. If not, I might suggest we add it somewhere for people trying to write a mod that doesn't crash. Thank you !!!  
    • I will keep adding to this thread with more information in case anyone can help, or at the very least I can keep my troubleshooting organized. I decided to downgrade to 54.1.0 in the hopes that this would fix the issue but it didn't. At least now I am on a "recommended" version. The crash report did confirm my earlier post that the Exception is coming from effectiveDescriptionId(). I'll continue to see if I can find a way to set the ID manually.   Caused by: java.lang.NullPointerException: Item id not set         at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item$Properties.effectiveDescriptionId(Item.java:465) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item.<init>(Item.java:111) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ShotgunItem.<init>(ShotgunItem.java:19) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ModItems.lambda$static$0(ModItems.java:15) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.lambda$handleEvent      
    • It just randomly stop working after a rebooted my dedicated server PLEASE HELP!   com.google.gson   Failed to start the minecraft server com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $  
  • Topics

×
×
  • Create New...

Important Information

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