net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData Java Examples

The following examples show how to use net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FMLPlayMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void encode(SpawnEntity msg, PacketByteBuf buf) {
	buf.writeVarInt(msg.typeId);
	buf.writeInt(msg.entityId);
	buf.writeUuid(msg.uuid);
	buf.writeDouble(msg.posX);
	buf.writeDouble(msg.posY);
	buf.writeDouble(msg.posZ);
	buf.writeByte(msg.pitch);
	buf.writeByte(msg.yaw);
	buf.writeByte(msg.headYaw);
	buf.writeShort(msg.velX);
	buf.writeShort(msg.velY);
	buf.writeShort(msg.velZ);

	if (msg.entity instanceof IEntityAdditionalSpawnData) {
		((IEntityAdditionalSpawnData) msg.entity).writeSpawnData(buf);
	}
}
 
Example #2
Source File: FMLPlayMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void handle(SpawnEntity msg, PacketContext context) {
	PatchworkNetworking.enqueueWork(context.getTaskQueue(), () -> {
		EntityType<?> type = Registry.ENTITY_TYPE.get(msg.typeId);

		if (type.equals(Registry.ENTITY_TYPE.get(Registry.ENTITY_TYPE.getDefaultId()))) {
			throw new RuntimeException(String.format("Could not spawn entity (id %d) with unknown type at (%f, %f, %f)", msg.entityId, msg.posX, msg.posY, msg.posZ));
		}

		ClientWorld world = MinecraftClient.getInstance().world;

		Entity entity = ((ClientEntitySpawner<?>) type).customClientSpawn(msg, world);

		if (entity == null) {
			return;
		}

		entity.updateTrackedPosition(msg.posX, msg.posY, msg.posZ);
		entity.updatePositionAndAngles(msg.posX, msg.posY, msg.posZ, (msg.yaw * 360) / 256.0F, (msg.pitch * 360) / 256.0F);
		entity.setHeadYaw((msg.headYaw * 360) / 256.0F);
		entity.setYaw((msg.headYaw * 360) / 256.0F);

		entity.setEntityId(msg.entityId);
		entity.setUuid(msg.uuid);
		world.addEntity(msg.entityId, entity);
		entity.setVelocity(msg.velX / 8000.0, msg.velY / 8000.0, msg.velZ / 8000.0);

		if (entity instanceof IEntityAdditionalSpawnData) {
			((IEntityAdditionalSpawnData) entity).readSpawnData(msg.buf);
		}
	});
}