Jump to content

Recommended Posts

Posted

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);

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.

Posted

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.

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.

Posted

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]);
}

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.

Posted

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));
}

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.

Posted

PacketBuffer

also has

readBlockPos

/

writeBlockPos

:P

 

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

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.

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.