Jump to content

[1.12]Registering Packets


ArmamentHaki

Recommended Posts

I wanted to create a packet which sends one ArrayList of an specific object from the Server to the Client. But first of all I don't understand this REQ-stuff. Has this to do with requests and replies?
Next, if I uderstand this right, Networking works the same way in either Singleplayer or Multiplayer, doesn't it? I have an issue regarding the registry of my packet. In Eclipse it says

Quote

The method registerMessage(Class<? extends IMessageHandler<REQ,REPLY>>, Class<REQ>, int, Side) in the type SimpleNetworkWrapper is not applicable for the arguments (Class<HandlerPacketCard>, Class<PacketCards>, int, Side)

And voilá my classes:

package armamenthaki.duelmonsters.network;

import java.util.ArrayList;

import armamenthaki.duelmonsters.DuelMonsters;
import armamenthaki.duelmonsters.duel.Card;
import armamenthaki.duelmonsters.individual.capabilities.IDuelData;
import armamenthaki.duelmonsters.network.message.HandlerPacketCard;
import armamenthaki.duelmonsters.network.message.PacketCard;
import armamenthaki.duelmonsters.network.message.PacketCards;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;

public class NetworkHandler 
{
	private static SimpleNetworkWrapper INSTANCE; 
	
	public static void init()
	{
		INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(DuelMonsters.MODID);
		INSTANCE.registerMessage(HandlerPacketCard.class, PacketCards.class, 0, Side.SERVER); 		//error this line

	}
}
package armamenthaki.duelmonsters.network.message;

import java.util.ArrayList;

import armamenthaki.duelmonsters.duel.Card;
import armamenthaki.duelmonsters.duel.cards.CardSpeedWarrior;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class HandlerPacketCard implements IMessageHandler
{

	@Override
	public IMessage onMessage(IMessage message, MessageContext ctx) 
	{
		if(ctx.side == Side.SERVER)
		{
			return new PacketCards(new ArrayList<Card>(), 0);
		}
		return null;
	}
	
}
package armamenthaki.duelmonsters.network.message;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import armamenthaki.duelmonsters.duel.Card;
import armamenthaki.duelmonsters.network.MessageBase;
import armamenthaki.duelmonsters.util.ByteBufUtil;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class PacketCards implements IMessage 
{
	private ArrayList<Card> cards;
	private ArrayList<Card> cardOP;
	ByteBufUtil bbu;
	ArrayList<byte[]> byteArray;
	private int intention;
	
	public PacketCards(ArrayList<Card> arrayCards, int intention)
	{
		this.cards = arrayCards;
		this.intention = intention;
	}
	
	@Override
	public void fromBytes(ByteBuf buf) 
	{
		int i = 0;
		ArrayList<Card> arrayCards = new ArrayList<Card>();
		for(Card card: cardOP)
		{
			try {
				buf.readBytes(byteArray.get(i));
				Card c = (Card) bbu.bytesToObj(byteArray.get(i));
				this.cards.add(c);
				i++;
			} catch (ClassNotFoundException | IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	@Override
	public void toBytes(ByteBuf buf) 
	{
		for(Card card: cards)
		{
			try {
				byte[] byteArray = bbu.objToBytes(card);
				cardOP.add(card);
				cards.remove(card);
				buf.writeBytes(byteArray);
				this.byteArray.add(byteArray);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

To write my Objects to Bytes, I use this ByteBufUtil:

package armamenthaki.duelmonsters.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ByteBufUtil 
{
	public static byte[] objToBytes(Object obj) throws IOException
	{
		byte[] bytes = null;
		ByteArrayOutputStream bos = null;
		ObjectOutputStream oos = null;
		try
		{
			bos = new ByteArrayOutputStream();
			oos = new ObjectOutputStream(bos);
			oos.writeObject(obj);
			oos.flush();
			bytes = bos.toByteArray();
		} 
		finally
		{
			if(oos != null)oos.close();
			if(bos != null)bos.close();
		}
		return bytes;
	}
	
	public static Object bytesToObj(byte[] bytes) throws IOException, ClassNotFoundException
	{
		Object obj = null;
		ByteArrayInputStream bis = null;
		ObjectInputStream ois = null;
		try
		{
			bis = new ByteArrayInputStream(bytes);
			ois = new ObjectInputStream(bis);
			obj = ois.readObject();
		} 
		finally
		{
			if(ois != null)ois.close();
			if(bis != null)bis.close();
		}
		return obj;
	}
}


Thank you for taking your time to help me.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

You should check out the documentation on networking.

Fine, I did that and it helped me. However I have a question. After I use the sendTo() command, what will the packet do? How can I Change for example an Attribute of a class based on the packet?
 

package armamenthaki.duelmonsters.network.message;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import armamenthaki.duelmonsters.duel.Card;
import armamenthaki.duelmonsters.network.MessageBase;
import armamenthaki.duelmonsters.util.ByteBufUtil;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class PacketCards<REQ> implements IMessage 
{
	public static HandlerPacketCards handler = new HandlerPacketCards();
	private ArrayList<Card> cards;
	private ArrayList<Card> cardOP;
	ByteBufUtil bbu;
	ArrayList<byte[]> byteArray;
	private int intention;
	
	public PacketCards(ArrayList<Card> arrayCards, int intention)
	{
		this.cards = arrayCards;
		this.intention = intention;
	}
	
	@Override
	public void fromBytes(ByteBuf buf) 
	{
		int i = 0;
		ArrayList<Card> arrayCards = new ArrayList<Card>();
		for(Card card: cardOP)
		{
			try {
				buf.readBytes(byteArray.get(i));
				Card c = (Card) bbu.bytesToObj(byteArray.get(i));
				this.cards.add(c);
				i++;
			} catch (ClassNotFoundException | IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	@Override
	public void toBytes(ByteBuf buf) 
	{
		for(Card card: cards)
		{
			try {
				byte[] byteArray = bbu.objToBytes(card);
				cardOP.add(card);
				cards.remove(card);
				buf.writeBytes(byteArray);
				this.byteArray.add(byteArray);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	static class HandlerPacketCards implements IMessageHandler<PacketCards, IMessage>
	{

		@Override
		public IMessage onMessage(PacketCards message, MessageContext ctx) 
		{
			if(ctx.side == Side.SERVER)
			{
				return new PacketCards(new ArrayList<Card>(), 0);
			}
			return null;
		}
	}
}


So, the Logical Server sends this packet object to the Logical Client, doesn't it? But where do I get the ArrayList from that I sent?

Link to comment
Share on other sites

Don't create a new packet in the handler, use the data from the one you receive as an argument to perform the desired action.

 

Don't write objects directly to bytes, write the identifier (if it's a singleton) or the individual primitive/string values (if it's not). If you use the Forge registry system for your Card class, you can use ByteBufUtils.readRegistryEntries and ByteBufUtils.writeRegistryEntries to read/write a collection of Cards to/from the byte buffer.

 

You never assign a value to the cardOP field and even if you did, you can't iterate through it in fromBytes. When a packet is received, it's constructed with the no-argument constructor (which your class is missing) and fromBytes is called to read data from the byte buffer and store it in the appropriate fields. The handler then uses the data from these fields.

 

The REQ type argument is pointless.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

So what I did was
-use the packet I receive in the handler
-understand how packets work
-add the empty constructor
-remove the REQ Argument
Thanks a lot, so far that really helped me out, mainly because I understand how it works now!

But I still have some Problems.
First off, how else should I write the objects to Bytes? What do you mean by identifier, because  I don't know how to acces an identifier of an object.
Then, does the Forge Registry also allow to Register non-Minecraft things? If so, that would also solve my Problem.


 

Edited by ArmamentHaki
Link to comment
Share on other sites

1 hour ago, ArmamentHaki said:

First off, how else should I write the objects to Bytes? What do you mean by identifier, because  I don't know how to acces an identifier of an object.

 

Are your Card objects singletons? Do they have some sort of unique identifier (e.g. a numeric or textual ID)? If they do, write this to the buffer in toBytes then read it from the buffer in fromBytes and use it look up the Card object in the master list/registry.

 

 

1 hour ago, ArmamentHaki said:

Then, does the Forge Registry also allow to Register non-Minecraft things? If so, that would also solve my Problem.

 

Yes, see the documentation on registries.

 

If you use a Forge registry, the ByteBufUtils methods I mentioned in my previous post handle reading/writing the ID and looking it up in the registry.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

So, thanks to your advice I tried creating a new Registry, the "CardRegistry". But, because of my lack of experience in modding and not really understanding the docs I will Show you what I have done so far. Hopefully it's not completely wrong:

I began with creating a new method in my main EventHandler, which should be called to Register my Card Registry.
There, I created a RegistryBuilder and used ist methods to define my Registry. However, I don't really understand the setName() and setDefaultKey methods,
and in the doc it said that it would have something to do with registryNames.
 

	@SubscribeEvent
	public static void registerCardRegistry(RegistryEvent.NewRegistry e)
	{
		RegistryBuilder regBuilder = new RegistryBuilder();
		regBuilder.setType(Card.class);
    	regBuilder.setName(new ResourceLocation(DuelMonsters.MODID, "textures/cards"));
    	regBuilder.setIDRange(0, 1000);
    	regBuilder.setDefaultKey(new ResourceLocation (DuelMonsters.MODID, "textures/cards"));
    	regBuilder.create();
	}

 

After that, I created a CardRegistry class, implementing IForgeRegistryEntry:
 

package armamenthaki.duelmonsters;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.IForgeRegistry;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;

public class CardRegistry<T> implements IForgeRegistryEntry<T>
{

	@Override
	public T setRegistryName(ResourceLocation name) {
		return null;
	}

	@Override
	public ResourceLocation getRegistryName() {
		return null;
	}

	@Override
	public Class<T> getRegistryType() {
		return null;
	}
}

 

At last, I tried this for the future registries of  my Cards:
 

@SubscribeEvent
public static void registerCards(RegistryEvent.Register e)
{
}

I think I Need to inform myself about type Parameters, because I didn't manage to define a certain registry Event here.
Still, is this a right way to do it, or is it completely wrong?

Edit:
Yes, my Cards have a unique ID and Names, so it would be possible to do something like

Card card;
if(message.id == 1)
{
	card = new CardExample();
}


, but I think it would be a very long method as I am planning to add many more Cards. Also, I think registering is a better way to do it.

Edited by ArmamentHaki
Link to comment
Share on other sites

The name of the registry should be something like <modid>:cards, not <modid>:textures/cards. It's a unique name for the registry, not a texture path.

 

The default key of the registry is the registry name of the default value. This is optional, the Block registry uses minecraft:air (the registry name of Blocks.AIR) and the PotionType registry uses minecraft:empty (the registry name of PotionTypes.EMPTY); but the other vanilla registries don't specify a default key.

 

You need to implement IForgeRegistryEntry on Card, the super type of the registry. Do this by extending IForgeRegistryEntry.Impl. Delete the CardRegistry class.

 

You should create a class like ForgeRegistries to store the IForgeRegistry<Card> instance (the Card registry), using GameRegistry.findRegistry to initialise the field. Make sure you only reference this class after RegistryEvent.NewRegistry is fired (e.g. in your RegistryEvent.Register<Card> handler).

 

You need to register your Card instances in RegistryEvent.Register<Card>.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Sorry for bothering, but I still get an error when recompiling:
 

Quote

Bound mismatch: The type Card is not a valid substitute for the bounded parameter <V extends IForgeRegistryEntry<V>> of the type IForgeRegistry<V>

This is what I changed:
Deleted CardRegistry class
Added Registries class:
 

package armamenthaki.duelmonsters;

import armamenthaki.duelmonsters.duel.Card;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.IForgeRegistry;

public class Registries 
{	
	public static final IForgeRegistry<Card> CARDREGISTRY = GameRegistry.findRegistry(Card.class); //error at <Card>
}


Also, I changed the Card class:

 

//I'll cut off the unimportant stuff

public class Card extends IForgeRegistryEntry.Impl {
	private String name;
	private int id;
	private ResourceLocation resource; //this is a resource location is used earlier for a GUI	


And thats what I changed in the EventHandler:

@SubscribeEvent
	public static void registerCardRegistry(RegistryEvent.NewRegistry e)
	{
		RegistryBuilder regBuilder = new RegistryBuilder();
		regBuilder.setType(Card.class);
    	regBuilder.setName(new ResourceLocation (DuelMonsters.MODID, "cards"));
    	regBuilder.setIDRange(0, 1000);
    	regBuilder.create();
	}
	
	@SubscribeEvent
	public static void registerCards(RegistryEvent.Register<Card> e)
	{
		Card speedwarrior = new CardSpeedWarrior(); //example registry
		e.getRegistry().register(speedwarrior);
	}

 

Edited by ArmamentHaki
Link to comment
Share on other sites

IForgeRegistryEntry.Impl is a generic type, you need to specify the type argument. In this case, use Card as the type argument (since that's the super type of the registry).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

2 hours ago, Choonster said:

IForgeRegistryEntry.Impl is a generic type, you need to specify the type argument. In this case, use Card as the type argument (since that's the super type of the registry).

All done. However, my game crashes upon initializing the Items. This happens because when an ItemCard is created, I assign a Card to it, which then can be transferred from the original item into the players' Card reposotory. I guess that it crashes because my Cards aren't registered yet, but Items always get registered second, as it says in the doc, so what should I do?

 

2017-07-10 18:03:20,609 main WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream
2017-07-10 18:03:20,609 main WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream
[18:03:20] [main/INFO] [GradleStart]: Extra: []
[18:03:20] [main/INFO] [GradleStart]: Running with arguments: [--userProperties, {}, --assetsDir, C:/Users/luca/.gradle/caches/minecraft/assets, --assetIndex, 1.12, --accessToken{REDACTED}, --version, 1.12, --tweakClass, net.minecraftforge.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.tweakers.CoremodTweaker]
[18:03:21] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Using primary tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.CoremodTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLTweaker
[18:03:21] [main/INFO] [FML]: Forge Mod Loader version 14.21.0.2327 for Minecraft 1.12 loading
[18:03:21] [main/INFO] [FML]: Java is Java HotSpot(TM) 64-Bit Server VM, version 1.8.0_131, running on Windows 7:amd64:6.1, installed at C:\Program Files\Java\jdk1.8.0_131\jre
[18:03:21] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation
[18:03:21] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.CoremodTweaker
[18:03:21] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.fml.relauncher.FMLCorePlugin
[18:03:21] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin
[18:03:21] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.AccessTransformerTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[18:03:21] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[18:03:21] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!
[18:03:23] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing
[18:03:23] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[18:03:23] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[18:03:24] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.AccessTransformerTweaker
[18:03:25] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.TerminalTweaker
[18:03:25] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.TerminalTweaker
[18:03:25] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}
2017-07-10 18:03:26,402 main WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream
2017-07-10 18:03:27,542 main WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream
2017-07-10 18:03:27,542 main WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream
[18:03:28] [main/INFO]: Setting user: Player226
[18:03:34] [main/WARN]: Skipping bad option: lastServer:
[18:03:34] [main/INFO]: LWJGL Version: 2.9.4
[18:03:36] [main/INFO] [FML]: -- System Details --
Details:
	Minecraft Version: 1.12
	Operating System: Windows 7 (amd64) version 6.1
	Java Version: 1.8.0_131, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 898984040 bytes (857 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
	JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
	IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
	FML: 
	Loaded coremods (and transformers): 
	GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.2.11481 Compatibility Profile Context' Renderer: 'AMD Radeon HD 7560D'
[18:03:36] [main/INFO] [FML]: MinecraftForge v14.21.0.2327 Initialized
[18:03:37] [main/INFO] [FML]: Replaced 921 ore ingredients
[18:03:37] [main/INFO] [FML]: Found 0 mods from the command line. Injecting into mod discoverer
[18:03:37] [main/INFO] [FML]: Searching C:\Users\luca\Diebe im Olymp CD\Desktop\Duel Monsters 1.12\DuelMonsters\mods for mods
[18:03:39] [main/INFO] [FML]: Forge Mod Loader has identified 5 mods to load
[18:03:39] [Thread-3/INFO] [FML]: Using sync timing. 200 frames of Display.update took 615174247 nanos
[18:03:40] [main/INFO] [FML]: Attempting connection with missing mods [minecraft, mcp, FML, forge, duelmonsters] at CLIENT
[18:03:40] [main/INFO] [FML]: Attempting connection with missing mods [minecraft, mcp, FML, forge, duelmonsters] at SERVER
[18:03:41] [main/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Duel Monsters
[18:03:41] [main/INFO] [FML]: Processing ObjectHolder annotations
[18:03:41] [main/INFO] [FML]: Found 464 ObjectHolder annotations
[18:03:41] [main/INFO] [FML]: Identifying ItemStackHolder annotations
[18:03:41] [main/INFO] [FML]: Found 0 ItemStackHolder annotations
[18:03:41] [main/INFO] [FML]: Applying holder lookups
[18:03:41] [main/INFO] [FML]: Holder lookups applied
[18:03:41] [main/INFO] [FML]: Applying holder lookups
[18:03:41] [main/INFO] [FML]: Holder lookups applied
[18:03:41] [main/INFO] [FML]: Applying holder lookups
[18:03:41] [main/INFO] [FML]: Holder lookups applied
[18:03:42] [main/INFO] [FML]: Configured a dormant chunk cache size of 0
[18:03:42] [Forge Version Check/INFO] [ForgeVersionCheck]: [forge] Starting version check at http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json
[18:03:42] [main/INFO] [duelmonsters]: preInit
[18:03:42] [main/INFO] [FML]: Applying holder lookups
[18:03:42] [main/INFO] [FML]: Holder lookups applied
[18:03:42] [main/INFO] [FML]: Injecting itemstacks
[18:03:42] [main/INFO] [FML]: Itemstack injection complete
[18:03:42] [Forge Version Check/INFO] [ForgeVersionCheck]: [forge] Found status: OUTDATED Target: 14.21.1.2387
[18:03:48] [Sound Library Loader/INFO]: Starting up SoundSystem...
[18:03:48] [Thread-5/INFO]: Initializing LWJGL OpenAL
[18:03:48] [Thread-5/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[18:03:49] [Thread-5/INFO]: OpenAL initialized.
[18:03:49] [Sound Library Loader/INFO]: Sound engine started
[18:03:56] [main/INFO] [FML]: Max texture size: 16384
[18:03:56] [main/INFO]: Created: 16x16 textures-atlas
[18:03:58] [main/INFO] [duelmonsters]: initItems
[18:03:58] [main/ERROR] [FML]: Fatal errors were detected during the transition from INITIALIZATION to POSTINITIALIZATION. Loading cannot continue
[18:03:58] [main/ERROR] [FML]: 
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
	UCHI	minecraft{1.12} [Minecraft] (minecraft.jar) 
	UCHI	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
	UCHI	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.12-14.21.0.2327.jar) 
	UCHI	forge{14.21.0.2327} [Minecraft Forge] (forgeSrc-1.12-14.21.0.2327.jar) 
	UCHE	duelmonsters{alpha 1.0} [Duel Monsters] (bin) 
[18:03:58] [main/ERROR] [FML]: The following problems were captured during this phase
[18:03:58] [main/ERROR] [FML]: Caught exception from Duel Monsters (duelmonsters)
java.lang.NullPointerException: null
	at net.minecraftforge.fml.common.registry.PersistentRegistryManager.makeDelegate(PersistentRegistryManager.java:729) ~[forgeSrc-1.12-14.21.0.2327.jar:?]
	at net.minecraftforge.fml.common.registry.IForgeRegistryEntry$Impl.<init>(IForgeRegistryEntry.java:70) ~[forgeSrc-1.12-14.21.0.2327.jar:?]
	at armamenthaki.duelmonsters.duel.Card.<init>(Card.java:13) ~[bin/:?]
	at armamenthaki.duelmonsters.duel.cards.cardtypes.CardMonster.<init>(CardMonster.java:14) ~[bin/:?]
	at armamenthaki.duelmonsters.duel.cards.CardSpeedWarrior.<init>(CardSpeedWarrior.java:13) ~[bin/:?]
	at armamenthaki.duelmonsters.init.Itemizer.initItems(Itemizer.java:28) ~[bin/:?]
	at armamenthaki.duelmonsters.DuelMonsters.init(DuelMonsters.java:59) ~[bin/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:643) ~[forgeSrc-1.12-14.21.0.2327.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76) ~[guava-21.0.jar:?]
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.EventBus.post(EventBus.java:217) ~[guava-21.0.jar:?]
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:252) ~[forgeSrc-1.12-14.21.0.2327.jar:?]
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:230) ~[forgeSrc-1.12-14.21.0.2327.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76) ~[guava-21.0.jar:?]
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116) ~[guava-21.0.jar:?]
	at com.google.common.eventbus.EventBus.post(EventBus.java:217) ~[guava-21.0.jar:?]
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:147) [LoadController.class:?]
	at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:830) [Loader.class:?]
	at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:358) [FMLClientHandler.class:?]
	at net.minecraft.client.Minecraft.init(Minecraft.java:571) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:411) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:26) [start/:?]
[18:03:58] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:629]: ---- Minecraft Crash Report ----
// On the bright side, I bought you a teddy bear!

Time: 7/10/17 6:03 PM
Description: There was a severe problem during mod loading that has caused the game to fail

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Duel Monsters (duelmonsters)
Caused by: java.lang.NullPointerException
	at net.minecraftforge.fml.common.registry.PersistentRegistryManager.makeDelegate(PersistentRegistryManager.java:729)
	at net.minecraftforge.fml.common.registry.IForgeRegistryEntry$Impl.<init>(IForgeRegistryEntry.java:70)
	at armamenthaki.duelmonsters.duel.Card.<init>(Card.java:13)
	at armamenthaki.duelmonsters.duel.cards.cardtypes.CardMonster.<init>(CardMonster.java:14)
	at armamenthaki.duelmonsters.duel.cards.CardSpeedWarrior.<init>(CardSpeedWarrior.java:13)
	at armamenthaki.duelmonsters.init.Itemizer.initItems(Itemizer.java:28)
	at armamenthaki.duelmonsters.DuelMonsters.init(DuelMonsters.java:59)
	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:498)
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:643)
	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:498)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:252)
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:230)
	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:498)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:147)
	at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:830)
	at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:358)
	at net.minecraft.client.Minecraft.init(Minecraft.java:571)
	at net.minecraft.client.Minecraft.run(Minecraft.java:411)
	at net.minecraft.client.main.Main.main(Main.java:118)
	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:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	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:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)


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

-- System Details --
Details:
	Minecraft Version: 1.12
	Operating System: Windows 7 (amd64) version 6.1
	Java Version: 1.8.0_131, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 662075416 bytes (631 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
	JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
	IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
	FML: MCP 9.40 Powered by Forge 14.21.0.2327 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
	UCHI	minecraft{1.12} [Minecraft] (minecraft.jar) 
	UCHI	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
	UCHI	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.12-14.21.0.2327.jar) 
	UCHI	forge{14.21.0.2327} [Minecraft Forge] (forgeSrc-1.12-14.21.0.2327.jar) 
	UCHE	duelmonsters{alpha 1.0} [Duel Monsters] (bin) 
	Loaded coremods (and transformers): 
	GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.2.11481 Compatibility Profile Context' Renderer: 'AMD Radeon HD 7560D'
[18:03:58] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:629]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\luca\Desktop\Duel Monsters 1.12\DuelMonsters\.\crash-reports\crash-2017-07-10_18.03.58-client.txt
AL lib: (EE) alc_cleanup: 1 device not closed
[0x7FEE55CAAA0] ANOMALY: meaningless REX prefix used
[0x7FEE55B48C0] ANOMALY: meaningless REX prefix used
[0x7FEE55B8BE0] ANOMALY: meaningless REX prefix used


 

Link to comment
Share on other sites

If Cards are in a Forge registry, you won't be able to reference them from your Item constructors.

 

I'm not sure how your code is currently set up, but I recommend using a single Item that stores the Card in the ItemStack's NBT (as the registry name) or capabilities (as a reference to the Card instance). This way you'll have a single Item instance that can be any card type and you won't be referencing the Card instances in your Item constructors.

 

If cards need custom behaviours in item form, create methods in Card matching the Item methods you need and override the Item methods to call the corresponding Card methods.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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



×
×
  • Create New...

Important Information

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