Jump to content

[1.7.10] [SOLVED] need a few tips about IExtendedEntityProperties


kauan99

Recommended Posts

my implementation of IExtendedEntityProperties adds 3 extra equipment slots.

 

I need to know for sure a few things first. I will probably have more questions latter, but I need the answer for these in order to realize the others:

 

when exactly is the EntityConstructing event raised? Does it get raised more than once for each player during a session?

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

Use your IDE's Find Usages/Call Hierarchy feature to look for usages of

EntityConstructingEvent

and you'll see that it's fired from the

Entity

constructor.

 

If you look for usages of

EntityPlayerMP

(the server-side player class), you'll see a new instance is created when a player logs into the server (

ServerConfigurationManager#createPlayerForUser

) or respawns after dying or conquering the End (

ServerConfigurationManager#respawnPlayer

).

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

Use your IDE's Find Usages/Call Hierarchy feature to look for usages of

EntityConstructingEvent

and you'll see that it's fired from the

Entity

constructor.

 

If you look for usages of

EntityPlayerMP

(the server-side player class), you'll see a new instance is created when a player logs into the server (

ServerConfigurationManager#createPlayerForUser

) or respawns after dying or conquering the End (

ServerConfigurationManager#respawnPlayer

).

 

thanks. it's very confusing to me because the type hierarchy of

EntityPlayer

is a bit complex, and the call hierarchy of the methods that instantiate new players is also confusing and undocumented and goes through methods without human friendly names.

 

So I can safely assume a new EntityPlayerMP will only be instantiated when one of these two FML events are raised:

 

1)

PlayerEvent.PlayerLoggedInEvent

2)

PlayerEvent.PlayerRespawnEvent

 

what about client side?

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

No, you cannot safely assume that. If you want to find out when a new player is instantiated, EntityConstructingEvent is the only choice you have.

 

then I will have to use some sort of 2 step initialization of my

IExtendedEntityProperties

, because I need access to fields from

EntityPlayer

which of course are all uninitialized during

EntityConstructing

due to the fact that it is raised from inside

Entity.<init>

. I will instantiate it during

EntityConstructing

and will have to initialize it at some point latter.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

Can I make these two assumptions?

 

1) while Minecraft client is running during gameplay, it has only one instance of

EntityClientPlayerMP

, corresponding to the player.

2) for each client connected, there is one corresponding

EntityPlayerMP

instance in the server, and that instance is disposed off when that client's connection is closed.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

I do the following to ensure that everytime a player joins the world they get an istance of my IEEP class. This event seems to cover allc ases (I havent found any cases where my IEEP isnt initialized.

 

@SubscribeEvent
public void onEntityConstructing(EntityConstructing event) {

	if (event.entity instanceof EntityPlayer) {
		if (CustomExtendedPlayerProperties.get((EntityPlayer) event.entity) == null) {
			CustomExtendedPlayerProperties.register((EntityPlayer) event.entity);
		}

	}
}

 

Then inside my IEEP

 

public static final CustomExtendedPlayerProperties get(EntityPlayer player) {
	return (CustomExtendedPlayerProperties) player.getExtendedProperties("CustomExtendedPlayerProperties");
}

 

public static final void register(EntityPlayer player) {
	player.registerExtendedProperties("CustomExtendedPlayerProperties", new CustomExtendedPlayerProperties(player));
}

 

Link to comment
Share on other sites

I do the following to ensure that everytime a player joins the world they get an istance of my IEEP class. This event seems to cover all cases (I havent found any cases where my IEEP isnt initialized.

 

that's the essence of the first part my solution, but since I need access to the players inventory to initialize my IEEP, and since that inventory is still null during the EntityConstructing event, that part of the solution alone wasn't enough. bellow is a simplified version of my code.

 

public class EventHandler
{
       @SubscribeEvent
public void onEntityConstructing(EntityConstructing event)
{
	if (event.entity instanceof EntityPlayerMP && XServerPlayer.get((EntityPlayerMP) event.entity) == null)
	{
		XServerPlayer.register((EntityPlayerMP)event.entity);
	}
	else if(event.entity instanceof EntityClientPlayerMP && XClientPlayer.get((EntityClientPlayerMP)event.entity) == null)
	{
		XClientPlayer.register((EntityClientPlayerMP) event.entity);
	}
}
}


public class XServerPlayer //(same code is valid for XClientPlayer)
{
        public static void register(EntityPlayerMP player)
{
	XServerPlayer xPlayer = new XServerPlayer(player);
	player.registerExtendedProperties("propertyName", xPlayer);

	//register for the first player tick only
	FMLCommonHandler.instance().bus().register(xPlayer);
}

        public void onPlayerFirstTick(PlayerTickEvent event)
{
	this.initialize();
	//unregister to stop receiving player tick events
	FMLCommonHandler.instance().bus().unregister(this);
}
}

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, Hi and I am making a forge 1.12.2 mod and also trying to get a custom model helmet item (I made a joker mask) and exported it to .json format and put it in the ~/namespace/models/item folder. Though, I'm struggling to get the item to render what I want it to be rendered like as I've positioned it in the 'head' window view in blockbench. How did you render out your model? I checked your code and it looks like no references to the actual model are being made. I'm new to this forge modding stuff (was a fabric modder) and I desperately need some help. Is there a way to standardly render out armor models made using blockbench? any methods that one can use? My model in JSON: ```json { "credit": "Made with Blockbench", "texture_size": [160, 160], "textures": { "0": "ydyrn:items/joker_mask_texture", "particle": "ydyrn:items/joker_mask_texture" }, "elements": [ { "from": [0, 0, 0], "to": [16, 16, 1], "faces": { "north": {"uv": [0, 1.7, 16, 14.2], "texture": "#0"}, "east": {"uv": [0, 4, 0.9, 5.6], "texture": "#0"}, "south": {"uv": [0, 5.8, 1.6, 7.4], "texture": "#0"}, "west": {"uv": [0, 1.9, 1.3, 3.5], "texture": "#0"}, "up": {"uv": [0, 3.4, 1.6, 4.2], "texture": "#0"}, "down": {"uv": [0, 9, 1.6, 9.7], "texture": "#0"} } }, { "from": [15.8, 11, 0.5], "to": [16.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } }, { "from": [0.2, 11, 14.6], "to": [15.8, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"} } }, { "from": [-0.2, 11, 0.5], "to": [0.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } } ], "display": { "thirdperson_righthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "thirdperson_lefthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "firstperson_righthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "firstperson_lefthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "ground": { "rotation": [40, 0, 0], "translation": [0, -2.5, 0], "scale": [0.5, 0.5, 0.5] }, "gui": { "rotation": [0, 180, 0] }, "head": { "translation": [0, 0, 0.25], "scale": [0.82773, 0.73594, 0.9] }, "fixed": { "translation": [0, 0, 8.75] } }, "groups": [ 0, { "name": "straps", "origin": [0, 0, 0], "color": 0, "children": [1, 2, 3] } ] } ```
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • In your config folder, delete the sophisticatedcore-common.toml file and test it again
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I am getting an error message that my mods and my server are not on the same minecraft version when they clearly are. My server and my mods are on 1.20.1 and the error says that the server is 1.20 even though it's on forge 47.2.30.  
×
×
  • Create New...

Important Information

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