Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.10] Custom Hanging Entity Issues
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Draco18s

[1.10] Custom Hanging Entity Issues

By Draco18s, November 17, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted November 17, 2016

I've created a custom hanging entity that I want to use to replace the ItemFrame so that I can supply some additional logic.

 

However, I have a couple issues.

If I don't register the mod entity, then the entity shows up and behaves normally, except that it doesn't save (this makes sense: there's no entity ID mapping for it).  However, if I add the registerModEntity line for it, then it doesn't show up in-game at all (???) but does save (as well as popping off if the block it's attached to is broken).

 

Main mod class:

			itemFrameReplacement = new ItemItemFrame();
	itemFrameReplacement.setRegistryName(new ResourceLocation("minecraft","item_frame"));
	itemFrameReplacement.setUnlocalizedName("frame");
	try {
		GameRegistry.addSubstitutionAlias("minecraft:item_frame", Type.ITEM, itemFrameReplacement);
	} catch (ExistingSubstitutionException e) {
		e.printStackTrace();
	}
	//commenting this line changes behavior:
	EntityRegistry.registerModEntity(EntityItemFrameReplacement.class, "item_frame_rep", 0, this, 48, 10, false);

  • Quote

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.

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted November 17, 2016

If you look at

EntityTrackerEntry::createSpawnPacket

you will see that item frames use a specialized spawn packet, which uses a special constructor to set the positional data. FMLs spawn mechanic doesn't do this and you have to emulate it using

IEntityAdditionalSpawnData

.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted November 17, 2016

If you look at

EntityTrackerEntry::createSpawnPacket

you will see that item frames use a specialized spawn packet, which uses a special constructor to set the positional data. FMLs spawn mechanic doesn't do this and you have to emulate it using

IEntityAdditionalSpawnData

.

 

Ahh. I wouldn't have even thought to look there.

Thanks.

  • Quote

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.

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted November 17, 2016

As there are very few posts about IEntityAdditionalSpawnData...

(Not that it was hard, but having the reference is nice!)

 

Make the custom entity implement it and then write this:

 

	@Override
public void writeSpawnData(ByteBuf buffer) {
	BlockPos p = getHangingPosition();
	buffer.writeInt(p.getX());
	buffer.writeInt(p.getY());
	buffer.writeInt(p.getZ());
	buffer.writeInt(this.getHorizontalFacing().getIndex());
}

@Override
public void readSpawnData(ByteBuf buffer) {
	BlockPos p = new BlockPos(buffer.readInt(),buffer.readInt(),buffer.readInt());
	this.hangingPosition = p;
	int f = buffer.readInt();
	updateFacingWithBoundingBox(EnumFacing.values()[f]);
}

  • Quote

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.

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted November 17, 2016

Just as a note, you can encode a

BlockPos

more easily and efficiently using either the method in

PacketBuffer

or

BlockPos::toLong

resp.

BlockPos.fromLong

.

If you use

PacketBuffer

that also has methods

readEnumValue

and

writeEnumValue

for maximum convenience :P

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted November 18, 2016

Just as a note, you can encode a

BlockPos

more easily and efficiently using either the method in

PacketBuffer

or

BlockPos::toLong

resp.

BlockPos.fromLong

.

If you use

PacketBuffer

that also has methods

readEnumValue

and

writeEnumValue

for maximum convenience :P

 

I wondered about that with the BlockPos, I hadn't seen anywhere a good way to encode it in packets (and vanilla decomposes it, or at least does for SPacketSpawnObject packet; see line 58).  Also, good to know about the read/write enum values.  Much handy.

 

Makes things

	@Override
public void writeSpawnData(ByteBuf buffer) {
	PacketBuffer pack = new PacketBuffer(buffer);
	pack.writeBlockPos(getHangingPosition());
	pack.writeEnumValue(this.getHorizontalFacing());
}

@Override
public void readSpawnData(ByteBuf buffer) {
	PacketBuffer pack = new PacketBuffer(buffer);
	hangingPosition = pack.readBlockPos();
	updateFacingWithBoundingBox(pack.readEnumValue(EnumFacing.class));
}

  • Quote

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.

Share this post


Link to post
Share on other sites

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted November 18, 2016
PacketBuffer

also has

readBlockPos

/

writeBlockPos

:P

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted November 18, 2016

PacketBuffer

also has

readBlockPos

/

writeBlockPos

:P

 

Oh, you put "or" and I read it as "and."  Thanks diesieben07.

  • Quote

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.

Share this post


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.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • kiou.23
      Block Rotate

      By kiou.23 · Posted 16 minutes ago

      That's usually the case, always try to understand the code before copy and pasting, or else you'll get a lot of headaches later in the code's life
    • Varzac
      Forge jar file not opening

      By Varzac · Posted 42 minutes ago

      I ran Jarfix and then tried installing again with the same results. Nothing happening I even tried using winrar, but as you said nothing happened
    • BeardlessBrady
      [1.16.4] Null when OpenGUI

      By BeardlessBrady · Posted 47 minutes ago

      Ah.. Thats what I get for stopping half way through and not double checking, thanks!
    • poopoodice
      [1.16.4] Null when OpenGUI

      By poopoodice · Posted 1 hour ago

      https://github.com/Beardlessbrady/Currency-Mod/blob/master-1.16/src/main/java/com/beardlessbrady/gocurrency/blocks/vending/VendingTile.java#L68 This should not be null.
    • -MCS_Gaming-
      Matchmaking System?

      By -MCS_Gaming- · Posted 1 hour ago

      I'm making an fps style mod and want to implement a matchmaking system, but I have absolutely no idea where to begin. Would anyone be able to give me some pointers as to how I would go about doing this?
  • Topics

    • ehbean
      10
      Block Rotate

      By ehbean
      Started 7 hours ago

    • Varzac
      3
      Forge jar file not opening

      By Varzac
      Started 13 hours ago

    • BeardlessBrady
      2
      [1.16.4] Null when OpenGUI

      By BeardlessBrady
      Started 1 hour ago

    • -MCS_Gaming-
      0
      Matchmaking System?

      By -MCS_Gaming-
      Started 1 hour ago

    • Nyko
      1
      [1.16.5] Beacon Overwrite (Screen Error)

      By Nyko
      Started 16 hours ago

  • Who's Online (See full list)

    • DieGo901yt
    • The_Deadly_Taco
    • brok4d
    • kiou.23
    • JackRaidenPH
    • NullDev
    • Jeldrik
    • ehbean
    • -MCS_Gaming-
    • Top_DawgsPM
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.10] Custom Hanging Entity Issues
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community